first commit

This commit is contained in:
2026-04-09 13:05:27 +02:00
commit 3bbd7d6413
3084 changed files with 84284 additions and 0 deletions

View File

@@ -0,0 +1,11 @@
/// <reference types="node" />
export interface FormDataEntry {
key: string;
value: string | Blob | Buffer;
fileName?: string;
}
export declare class FormData {
private _entries;
append(key: string, value: string | Blob | Buffer, fileName?: string): void;
}
export declare function getFormDataEntries(fd: FormData): FormDataEntry[];

View File

@@ -0,0 +1,16 @@
"use strict";
exports.__esModule = true;
var FormData = /** @class */ (function () {
function FormData() {
this._entries = [];
}
FormData.prototype.append = function (key, value, fileName) {
this._entries.push({ key: key, value: value, fileName: fileName });
};
return FormData;
}());
exports.FormData = FormData;
function getFormDataEntries(fd) {
return fd._entries;
}
exports.getFormDataEntries = getFormDataEntries;

View File

@@ -0,0 +1,17 @@
// @flow
// Generated using flowgen2
interface FormDataEntry {
key: string;
value: string | Blob | Buffer;
fileName?: string;
}
export type {FormDataEntry};
declare class FormData {
append(key: string, value: string | Blob | Buffer, fileName?: string): void;
}
export {FormData};
declare function getFormDataEntries(fd: FormData): Array<FormDataEntry>;
export {getFormDataEntries};

View File

@@ -0,0 +1,18 @@
/// <reference types="node" />
import { Options as AsyncOptions } from 'then-request';
import { FormData, FormDataEntry } from './FormData';
export interface BaseOptions extends Pick<AsyncOptions, 'allowRedirectHeaders' | 'followRedirects' | 'gzip' | 'headers' | 'maxRedirects' | 'maxRetries' | 'qs' | 'json'> {
agent?: boolean;
cache?: 'file';
retry?: boolean;
retryDelay?: number;
socketTimeout?: number;
timeout?: number;
body?: string | Buffer;
}
export interface Options extends BaseOptions {
form?: FormData;
}
export interface MessageOptions extends BaseOptions {
form?: FormDataEntry[];
}

View File

@@ -0,0 +1,2 @@
"use strict";
exports.__esModule = true;

View File

@@ -0,0 +1,27 @@
// @flow
// Generated using flowgen2
import type {Options as AsyncOptions} from 'then-request';
import {FormData} from './FormData';
import type {FormDataEntry} from './FormData';
interface BaseOptions {
agent?: boolean;
cache?: 'file';
retry?: boolean;
retryDelay?: number;
socketTimeout?: number;
timeout?: number;
body?: string | Buffer;
}
export type {BaseOptions};
interface Options {
form?: FormData;
}
export type {Options};
interface MessageOptions {
form?: Array<FormDataEntry>;
}
export type {MessageOptions};

View File

@@ -0,0 +1,7 @@
/// <reference types="node" />
import { URL } from 'url';
import { HttpVerb, Response } from 'then-request';
import { Options } from './Options';
declare const fd: any;
export { fd as FormData };
export default function doRequest(method: HttpVerb, url: string | URL, options?: Options): Response;

View File

@@ -0,0 +1,69 @@
"use strict";
exports.__esModule = true;
var handle_qs_js_1 = require("then-request/lib/handle-qs.js");
var GenericResponse = require("http-response-object");
var fd = FormData;
exports.FormData = fd;
function doRequest(method, url, options) {
var xhr = new XMLHttpRequest();
// check types of arguments
if (typeof method !== 'string') {
throw new TypeError('The method must be a string.');
}
if (url && typeof url === 'object') {
url = url.href;
}
if (typeof url !== 'string') {
throw new TypeError('The URL/path must be a string.');
}
if (options === null || options === undefined) {
options = {};
}
if (typeof options !== 'object') {
throw new TypeError('Options must be an object (or null).');
}
method = method.toUpperCase();
options.headers = options.headers || {};
// handle cross domain
var match;
var crossDomain = !!((match = /^([\w-]+:)?\/\/([^\/]+)/.exec(url)) && match[2] != location.host);
if (!crossDomain)
options.headers['X-Requested-With'] = 'XMLHttpRequest';
// handle query string
if (options.qs) {
url = handle_qs_js_1["default"](url, options.qs);
}
// handle json body
if (options.json) {
options.body = JSON.stringify(options.json);
options.headers['content-type'] = 'application/json';
}
if (options.form) {
options.body = options.form;
}
// method, url, async
xhr.open(method, url, false);
for (var name in options.headers) {
xhr.setRequestHeader(name.toLowerCase(), '' + options.headers[name]);
}
// avoid sending empty string (#319)
xhr.send(options.body ? options.body : null);
var headers = {};
xhr
.getAllResponseHeaders()
.split('\r\n')
.forEach(function (header) {
var h = header.split(':');
if (h.length > 1) {
headers[h[0].toLowerCase()] = h
.slice(1)
.join(':')
.trim();
}
});
return new GenericResponse(xhr.status, headers, xhr.responseText, url);
}
exports["default"] = doRequest;
module.exports = doRequest;
module.exports["default"] = doRequest;
module.exports.FormData = fd;

View File

@@ -0,0 +1,16 @@
// @flow
// Generated using flowgen2
import {URL} from 'url';
import type {HttpVerb} from 'then-request';
import type {Response} from 'then-request';
import type {Options} from './Options';
declare var fd: any;
export {fd as FormData};
declare function doRequest(
method: HttpVerb,
url: string | URL,
options?: Options,
): Response;
export default doRequest;

View File

@@ -0,0 +1,8 @@
/// <reference types="node" />
import { HttpVerb, Response } from 'then-request';
import { URL } from 'url';
import { FormData } from './FormData';
import { Options } from './Options';
export { HttpVerb, Response, Options };
export { FormData };
export default function request(method: HttpVerb, url: string | URL, options?: Options): Response;

View File

@@ -0,0 +1,34 @@
"use strict";
var __rest = (this && this.__rest) || function (s, e) {
var t = {};
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
t[p] = s[p];
if (s != null && typeof Object.getOwnPropertySymbols === "function")
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) if (e.indexOf(p[i]) < 0)
t[p[i]] = s[p[i]];
return t;
};
exports.__esModule = true;
var GenericResponse = require("http-response-object");
var FormData_1 = require("./FormData");
exports.FormData = FormData_1.FormData;
var init = require('sync-rpc');
var remote = init(require.resolve('./worker'));
function request(method, url, options) {
var _a = options || { form: undefined }, form = _a.form, o = __rest(_a, ["form"]);
var opts = o;
if (form) {
opts.form = FormData_1.getFormDataEntries(form);
}
var req = {
m: method,
u: url && typeof url === 'object' ? url.href : url,
o: opts
};
var res = remote(req);
return new GenericResponse(res.s, res.h, res.b, res.u);
}
exports["default"] = request;
module.exports = request;
module.exports["default"] = request;
module.exports.FormData = FormData_1.FormData;

View File

@@ -0,0 +1,19 @@
// @flow
// Generated using flowgen2
import type {HttpVerb} from 'then-request';
import type {Response} from 'then-request';
import {URL} from 'url';
import {FormData} from './FormData';
import type {Options} from './Options';
export type {HttpVerb};
export type {Response};
export type {Options};
export {FormData};
declare function request(
method: HttpVerb,
url: string | URL,
options?: Options,
): Response;
export default request;

View File

@@ -0,0 +1,13 @@
import { Response, HttpVerb } from 'then-request';
import { MessageOptions } from './Options';
export declare type Req = {
m: HttpVerb;
u: string;
o?: MessageOptions;
};
export interface Res {
s: Response['statusCode'];
h: Response['headers'];
b: Response['body'];
u: Response['url'];
}

View File

@@ -0,0 +1,2 @@
"use strict";
exports.__esModule = true;

View File

@@ -0,0 +1,17 @@
// @flow
// Generated using flowgen2
import type {Response} from 'then-request';
import type {HttpVerb} from 'then-request';
import type {MessageOptions} from './Options';
type Req = {m: HttpVerb, u: string, o?: MessageOptions};
export type {Req};
interface Res {
s: $PropertyType<Response, 'statusCode'>;
h: $PropertyType<Response, 'headers'>;
b: $PropertyType<Response, 'body'>;
u: $PropertyType<Response, 'url'>;
}
export type {Res};

View File

View File

@@ -0,0 +1,33 @@
"use strict";
var __rest = (this && this.__rest) || function (s, e) {
var t = {};
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
t[p] = s[p];
if (s != null && typeof Object.getOwnPropertySymbols === "function")
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) if (e.indexOf(p[i]) < 0)
t[p[i]] = s[p[i]];
return t;
};
exports.__esModule = true;
var then_request_1 = require("then-request");
function init() {
return function (req) {
// Note how even though we return a promise, the resulting rpc client will be synchronous
var _a = req.o || { form: undefined }, form = _a.form, o = __rest(_a, ["form"]);
var opts = o;
if (form) {
var fd_1 = new then_request_1.FormData();
form.forEach(function (entry) {
fd_1.append(entry.key, entry.value, entry.fileName);
});
opts.form = fd_1;
}
return then_request_1["default"](req.m, req.u, opts).then(function (response) { return ({
s: response.statusCode,
h: response.headers,
b: response.body,
u: response.url
}); });
};
}
module.exports = init;

View File

@@ -0,0 +1,2 @@
// @flow
// Generated using flowgen2