<commit_before>import { SNS } from "aws-sdk";
import { Topic, TopicsList, Subscription, ListSubscriptionsResponse, CreateTopicResponse } from "aws-sdk/clients/sns.d";
import fetch from "node-fetch";
import { IDebug, ISNSServer } from "./types";
import bodyParser = require("body-parser");
import { v4 as uuid } from "uuid";
import * as xml from "xml";
const createAttr = () => {
    return {
        _attr: {
            xmlns: "http://sns.amazonaws.com/doc/2010-03-31/",
        },
    };
};

const createMetadata = () => {
    return {
        ResponseMetadata: [{
            RequestId: uuid(),
        }],
    };
};

const arrayify = obj => {
    return Object.keys(obj).map(key => {
        const x = {};
        x[key] = obj[key];
        return x;
    });
};

const parseMessageAttributes = body => {
    if (body.MessageStructure !== "raw") {
        return {};
    }

    const entries = Object.keys(body)
        .filter(key => key.startsWith("MessageAttributes.entry"))
        .reduce(
            (prev, key) => {
                const index = key.replace("MessageAttributes.entry.", "").match(/.*?(?=\.|$)/i)[0];
                return prev.includes(index) ? prev : [...prev, index];
            },
            [],
        );
    return entries
        .map(index => `MessageAttributes.entry.${index}`)<commit_msg>MessageAttribute can work if MessageStructure !== 'json' (#19)<commit_after>import { SNS } from "aws-sdk";
import { Topic, TopicsList, Subscription, ListSubscriptionsResponse, CreateTopicResponse } from "aws-sdk/clients/sns.d";
import fetch from "node-fetch";
import { IDebug, ISNSServer } from "./types";
import bodyParser = require("body-parser");
import { v4 as uuid } from "uuid";
import * as xml from "xml";
const createAttr = () => {
    return {
        _attr: {
            xmlns: "http://sns.amazonaws.com/doc/2010-03-31/",
        },
    };
};

const createMetadata = () => {
    return {
        ResponseMetadata: [{
            RequestId: uuid(),
        }],
    };
};

const arrayify = obj => {
    return Object.keys(obj).map(key => {
        const x = {};
        x[key] = obj[key];
        return x;
    });
};

const parseMessageAttributes = body => {
    if (body.MessageStructure === "json") {
        return {};
    }

    const entries = Object.keys(body)
        .filter(key => key.startsWith("MessageAttributes.entry"))
        .reduce(
            (prev, key) => {
                const index = key.replace("MessageAttributes.entry.", "").match(/.*?(?=\.|$)/i)[0];
                return prev.includes(index) ? prev : [...prev, index];
            },
            [],
        );
    return entries
        .map(index => `MessageAttributes.entry.${index}`)
{'fraction_non_alphanumeric': 0.172209903917221, 'fraction_numerical': 0.008130081300813009, 'mean_word_length': 2.2303102625298328, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 6}, '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': '7274698', 'n_tokens_mistral': 824, 'n_tokens_neox': 814, 'n_words': 177}