<commit_before>/// <reference path="../../submodules/DefinitelyTyped/requirejs/require.d.ts"/>
/// <reference path="../../submodules/DefinitelyTyped/jquery/jquery.d.ts"/>

var obviel = require('obviel');

export function register_transformer() {

    // register global transformer to add obviel ifaces attribute to
    // the received json objects.  also runs s/\./#/g on property
    // sheet names.
    obviel.transformer(function(obj, path, name) {

        // strip noise from content type and property sheet types
        obj.content_type = 'C_' + obj.content_type.substring(obj.content_type.lastIndexOf(".") + 1);

        for (i in obj.data) {
            var i_local = 'P_' + i.substring(i.lastIndexOf(".") + 1);
            obj.data[i_local] = obj.data[i];
            delete obj.data[i];
        }

        // add content type to ifaces
        var main_interface = obj.content_type;
        if (typeof(main_interface) == 'undefined') {
            throw ("Object " + obj  + " from path " + path + " has no 'content_type' field");
        };
        obj.ifaces = [main_interface];

        // add all property sheet types as ifaces
        for (var i in obj.data) {
            obj.ifaces.push(i);
        };

        return obj;
    });
}


// out-transformer.  call this on every object before sending it back
// to the server.
export function make_postable(obj) {
    var i;

    obj.content_type = 'adhocracy.contents.interfaces.' + obj.content_type.substring(2);
    delete obj['ifaces'][0];

    for (i in obj['ifaces']) {
        var i_remote = 'adhocracy.contents.interfaces.' + i.substring(2);
        obj.data[i_remote] = obj.data[i];
        delete obj.data[i];
    }

    delete obj['ifaces'];
    delete obj['path'];
}<commit_msg>frontend: fix content type / property type conversion<commit_after>/// <reference path="../../submodules/DefinitelyTyped/requirejs/require.d.ts"/>
/// <reference path="../../submodules/DefinitelyTyped/jquery/jquery.d.ts"/>

var obviel = require('obviel');

export function register_transformer() {

    // register global transformer to add obviel ifaces attribute to
    // the received json objects.  also runs s/\./#/g on property
    // sheet names.
    obviel.transformer(function(obj, path, name) {

        // strip noise from content type and property sheet types
        obj.content_type = 'C_' + obj.content_type.substring(obj.content_type.lastIndexOf(".") + 1);

        for (i in obj.data) {
            var i_local = 'P_' + i.substring(i.lastIndexOf(".") + 1);
            obj.data[i_local] = obj.data[i];
            delete obj.data[i];
        }

        // add content type to ifaces
        var main_interface = obj.content_type;
        if (typeof(main_interface) == 'undefined') {
            throw ("Object " + obj  + " from path " + path + " has no 'content_type' field");
        };
        obj.ifaces = [main_interface];

        // add all property sheet types as ifaces
        for (var i in obj.data) {
            obj.ifaces.push(i);
        };

        return obj;
    });
}


// out-transformer.  call this on every object before sending it back
// to the server.
export function make_postable(obj) {
    var i;

    delete obj['ifaces'];
    delete obj['path'];

    obj.content_type = 'adhocracy.contents.interfaces.' + obj.content_type.substring(2);

    for (i in obj['data']) {
        var i_remote = 'adhocracy.propertysheets.interfaces.' + i.substring(2);
        obj.data[i_remote] = obj.data[i];
        delete obj.data[i];
    }
}
{'fraction_non_alphanumeric': 0.14164064717570252, 'fraction_numerical': 0.002554640931024695, 'mean_word_length': 2.359389895138227, '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': '2275170', 'n_tokens_mistral': 1095, 'n_tokens_neox': 1062, 'n_words': 278}