<commit_before>﻿import { ModelState } from './Signum.Entities'
import { Dic } from './Globals'
import { GraphExplorer } from './Reflection'

var fetchWithAbortModule = require('./fetchWithAbort') as { fetch: typeof fetch };

export interface AjaxOptions {
    url: string;
    avoidNotifyPendingRequests?: boolean;
    avoidThrowError?: boolean;
    avoidGraphExplorer?: boolean;
    avoidAuthToken?: boolean;
    avoidVersionCheck?: boolean;

    
    headers?: { [index: string]: string };
    mode?: string;
    credentials?: RequestCredentials;
    cache?: string;
    abortController?: FetchAbortController;
}


export function baseUrl(options: AjaxOptions): string {
    const baseUrl = window.__baseUrl;

    if (options.url.startsWith("~/"))
        return baseUrl + options.url.after("~/");

    return options.url;
}

export function ajaxGet<T>(options: AjaxOptions): Promise<T> {
    return ajaxGetRaw(options)
        .then(a => a.status == 204 ? undefined as any : a.json().then(a => a as T));
}

export function ajaxGetRaw(options: AjaxOptions) : Promise<Response> {
    return wrapRequest(options, () =>
        fetchWithAbortModule.fetch(baseUrl(options), {
            method: "GET",
            headers: {
                'Accept': 'application/json',
                ...options.headers
            } as any,
            mode: options.mode,
            credentials: options.credentials || "same-origin",
            cache: options.cache,
            abortController: options.abortController
        } as RequestInit));
}

export function ajaxPost<T>(options: AjaxOptions, data: any): Promise<T> {
    return ajaxPostRaw(options, data)
        .then(a => a.status == 204 ? undefined as any : a.json().then(a => a as T));
}

<commit_msg>fix empty response<commit_after>﻿import { ModelState } from './Signum.Entities'
import { Dic } from './Globals'
import { GraphExplorer } from './Reflection'

var fetchWithAbortModule = require('./fetchWithAbort') as { fetch: typeof fetch };

export interface AjaxOptions {
    url: string;
    avoidNotifyPendingRequests?: boolean;
    avoidThrowError?: boolean;
    avoidGraphExplorer?: boolean;
    avoidAuthToken?: boolean;
    avoidVersionCheck?: boolean;

    
    headers?: { [index: string]: string };
    mode?: string;
    credentials?: RequestCredentials;
    cache?: string;
    abortController?: FetchAbortController;
}


export function baseUrl(options: AjaxOptions): string {
    const baseUrl = window.__baseUrl;

    if (options.url.startsWith("~/"))
        return baseUrl + options.url.after("~/");

    return options.url;
}

export function ajaxGet<T>(options: AjaxOptions): Promise<T> {
    return ajaxGetRaw(options)
        .then(res => res.text())
        .then(text => text.length ? JSON.parse(text) : undefined);
}

export function ajaxGetRaw(options: AjaxOptions) : Promise<Response> {
    return wrapRequest(options, () =>
        fetchWithAbortModule.fetch(baseUrl(options), {
            method: "GET",
            headers: {
                'Accept': 'application/json',
                ...options.headers
            } as any,
            mode: options.mode,
            credentials: options.credentials || "same-origin",
            cache: options.cache,
            abortController: options.abortController
        } as RequestInit));
}

export function ajaxPost<T>(options: AjaxOptions, data: any): Promise<T> {
    return ajaxPostRaw(options, data)
        .then(res => res.text())
        .then(text => text.length ? JSON.parse(text) : undefined);
}


{'fraction_non_alphanumeric': 0.12990680598700932, 'fraction_numerical': 0.0016944365998305564, 'mean_word_length': 2.957541899441341, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 23, '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': '6517389', 'n_tokens_mistral': 1017, 'n_tokens_neox': 989, 'n_words': 244}