<commit_before>// ====================================================================
// XEP-0004: Data Forms
// --------------------------------------------------------------------
// Source: https://xmpp.org/extensions/xep-0004.html
// Version: 2.9 (2007-08-13)
// ====================================================================

import {
    attribute,
    childBoolean,
    childText,
    DefinitionOptions,
    multipleChildText,
    splicePath,
    TranslationContext,
    XMLElement
} from '../jxt';

import { NS_DATAFORM } from './Namespaces';
import { JID } from './util';

declare module './' {
    export interface Message {
        forms?: DataForm[];
    }
}

export interface DataForm {
    type?: 'form' | 'submit' | 'cancel' | 'result';
    title?: string;
    instructions?: string | string[];
    reported?: DataFormField[];
    items?: DataFormItem[];
    fields?: DataFormField[];
}

export interface DataFormItem {
    fields: DataFormField[];
}

export interface DataFormFieldBase {
    name?: string;
    label?: string;
    description?: string;
    required?: boolean;
    rawValues?: string[];
}

export interface DataFormFieldBoolean extends DataFormFieldBase {
    type: 'boolean';
    value?: boolean;
}

export interface DataFormFieldText extends DataFormFieldBase {
    type: 'fixed' | 'hidden' | 'text-private' | 'text-single';
    value?: string;
}

export interface DataFormFieldTextMulti extends DataFormFieldBase {
    type: 'text-multi';
    value?: string[];
}

export interface DataFormFieldList extends DataFormFieldBase {
    type: 'list-single';
    value?: string;
    options?: Array<DataFormFieldOption<string>>;
}

export interface DataFormFieldListMulti extends DataFormFieldBase {
    type: 'list-multi';
    value?: string[];
    options?: Array<DataFormFieldOption<string>>;
}

export interface DataFormFieldJID extends DataFormFieldBase {
    type: 'jid-single';
    value?: JID;
    options?: Array<DataFormFieldOption<JID>>;
}

export interface DataFormFieldJIDMulti extends DataFormFieldBase {
    type: 'jid-multi';
    value?: JID[];
    options?: Array<DataFormFieldOption<JID>>;
}

export interface DataFormFieldOption<T> {
    label?: string;
    value: T;
}

export type DataFormField =
    | DataFormFieldBoolean
    | DataFormFieldText
    | DataFormFieldTextMulti
    | DataFormFieldList
    | DataFormFieldListMulti
    | DataFormFieldJID
    | DataFormFieldJIDMulti;

export default [
    {
        aliases: [{ path: 'message.forms', multiple: true }],
        element: 'x',
        fields: {
            instructions: {
                ...multipleChildText(null, 'instructions'),
                exportOrder: 2
            },
            reported: {
                ...splicePath(null, 'reported', 'dataformField', true),
                exportOrder: 3
            },
            title: {
                ...childText(null, 'title'),
                exportOrder: 1
            },
            type: attribute('type')
        },<commit_msg>Allow Dataform fields to not specify a type when submitting.<commit_after>// ====================================================================
// XEP-0004: Data Forms
// --------------------------------------------------------------------
// Source: https://xmpp.org/extensions/xep-0004.html
// Version: 2.9 (2007-08-13)
// ====================================================================

import {
    attribute,
    childBoolean,
    childText,
    DefinitionOptions,
    multipleChildText,
    splicePath,
    TranslationContext,
    XMLElement
} from '../jxt';

import { NS_DATAFORM } from './Namespaces';
import { JID } from './util';

declare module './' {
    export interface Message {
        forms?: DataForm[];
    }
}

export interface DataForm {
    type?: 'form' | 'submit' | 'cancel' | 'result';
    title?: string;
    instructions?: string | string[];
    reported?: DataFormField[];
    items?: DataFormItem[];
    fields?: DataFormField[];
}

export interface DataFormItem {
    fields: DataFormField[];
}

export interface DataFormFieldBase {
    name?: string;
    label?: string;
    description?: string;
    required?: boolean;
    rawValues?: string[];
}

export interface DataFormFieldBoolean extends DataFormFieldBase {
    type: 'boolean';
    value?: boolean;
}

export interface DataFormFieldText extends DataFormFieldBase {
    type: 'fixed' | 'hidden' | 'text-private' | 'text-single';
    value?: string;
}

export interface DataFormFieldTextMulti extends DataFormFieldBase {
    type: 'text-multi';
    value?: string[];
}

export interface DataFormFieldList extends DataFormFieldBase {
    type: 'list-single';
    value?: string;
    options?: Array<DataFormFieldOption<string>>;
}

export interface DataFormFieldListMulti extends DataFormFieldBase {
    type: 'list-multi';
    value?: string[];
    options?: Array<DataFormFieldOption<string>>;
}

export interface DataFormFieldJID extends DataFormFieldBase {
    type: 'jid-single';
    value?: JID;
    options?: Array<DataFormFieldOption<JID>>;
}

export interface DataFormFieldJIDMulti extends DataFormFieldBase {
    type: 'jid-multi';
    value?: JID[];
    options?: Array<DataFormFieldOption<JID>>;
}

export interface DataFormFieldAny extends DataFormFieldBase {
    type?: undefined;
    value?: boolean | string | string[] | JID | JID[];
}

export interface DataFormFieldOption<T> {
    label?: string;
    value: T;
}

export type DataFormField =
    | DataFormFieldBoolean
    | DataFormFieldText
    | DataFormFieldTextMulti
    | DataFormFieldList
    | DataFormFieldListMulti
    | DataFormFieldJID
    | DataFormFieldJIDMulti
    | DataFormFieldAny;

export default [
    {
        aliases: [{ path: 'message.forms', multiple: true }],
        element: 'x',
        fields: {
            instructions: {
                ...multipleChildText(null, 'instructions'),
                exportOrder: 2
            },
            reported: {
                ...splicePath(null, 'reported', 'dataformField', true),
                exportOrder: 3
            },
            title: {
                ...childText(null, 'title'),
                exportOrder: 1
            },
            type: attribute('type')
        },
{'fraction_non_alphanumeric': 0.17843388960205392, 'fraction_numerical': 0.006739409499358151, 'mean_word_length': 2.7345715997603355, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 21, 'https://': 2, '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': '777668', 'n_tokens_mistral': 1738, 'n_tokens_neox': 1697, 'n_words': 407}