<commit_before>const warpjsUtils = require('@warp-works/warpjs-utils');

// const debug = require('./debug')('extract-document');
const Document = require('./../../../lib/core/first-class/document');
const extractCommunity = require('./extract-community');
const extractOverview = require('./extract-overview');
// const extractPageViewPanels = require('./extract-page-view-panels');
const serverUtils = require('./../../utils');

module.exports = async (req, persistence, type, id, viewName, level = 0) => {
    const entity = await serverUtils.getEntity(null, type);
    const document = await entity.getInstance(persistence, id);

    if (!document.id) {
        throw new warpjsUtils.WarpJSError(`Invalid document '${type}' with id='${id}'.`);
    }

    const isVisible = await Document.isVisible(persistence, entity, document, req.warpjsUser);
    if (!isVisible) {
        return null;
    }

    const resource = warpjsUtils.createResource(req, {
        type: document.type,
        typeID: document.typeID || entity.id,
        id: document.id,
        name: document.Name,
        lastUpdated: document.lastUpdated,
        status: document.Status
    }, req);

    if (!level) {
        // Add links only for top document.
        resource.link('home', {
            title: "Home",
            href: warpjsUtils.fullUrl(req, '/')
        });
    }

    const overview = await extractOverview(req, persistence, entity, document, viewName, level);
    resource.embed('items', overview);

    // Only keep the community at the first level.
    if (!level) {
        const authorsResource = await extractCommunity(req, persistence, entity, document, 'Authors');
        if (authorsResource) {
            resource.embed('items', authorsResource);
        }

        const contributorsResource = await extractCommunity(req, persistence, entity, document, 'Contributors');
        if (contributorsResource) {
            resource.embed('items', contributorsResource);
        }<commit_msg>- #235: Adding new editors association.<commit_after>const warpjsUtils = require('@warp-works/warpjs-utils');

// const debug = require('./debug')('extract-document');
const Document = require('./../../../lib/core/first-class/document');
const extractCommunity = require('./extract-community');
const extractOverview = require('./extract-overview');
// const extractPageViewPanels = require('./extract-page-view-panels');
const serverUtils = require('./../../utils');

module.exports = async (req, persistence, type, id, viewName, level = 0) => {
    const entity = await serverUtils.getEntity(null, type);
    const document = await entity.getInstance(persistence, id);

    if (!document.id) {
        throw new warpjsUtils.WarpJSError(`Invalid document '${type}' with id='${id}'.`);
    }

    const isVisible = await Document.isVisible(persistence, entity, document, req.warpjsUser);
    if (!isVisible) {
        return null;
    }

    const resource = warpjsUtils.createResource(req, {
        type: document.type,
        typeID: document.typeID || entity.id,
        id: document.id,
        name: document.Name,
        lastUpdated: document.lastUpdated,
        status: document.Status
    }, req);

    if (!level) {
        // Add links only for top document.
        resource.link('home', {
            title: "Home",
            href: warpjsUtils.fullUrl(req, '/')
        });
    }

    const overview = await extractOverview(req, persistence, entity, document, viewName, level);
    resource.embed('items', overview);

    // Only keep the community at the first level.
    if (!level) {
        const editorResources = await extractCommunity(req, persistence, entity, document, 'Editors');
        if (editorResources) {
            resource.embed('items', editorResources);
        }

        const authorsResource = await extractCommunity(req, persistence, entity, document, 'Authors');
        if (authorsResource) {
            resource.embed('items', authorsResource);
        }

        const contributorsResource = await extractCommunity(req, persistence, entity, document, 'Contributors');
        if (contributorsResource) {
            resource.embed('items', contributorsResource);
        }
{'fraction_non_alphanumeric': 0.13926453143534995, 'fraction_numerical': 0.0011862396204033216, 'mean_word_length': 2.988647114474929, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '3621492', 'n_tokens_mistral': 1147, 'n_tokens_neox': 1087, 'n_words': 287}