initial commit

This commit is contained in:
Zoe
2023-01-03 09:29:04 -06:00
commit 7851137d88
12889 changed files with 2557443 additions and 0 deletions

47
node_modules/unenv/runtime/fetch/call.cjs generated vendored Normal file
View File

@@ -0,0 +1,47 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.createCall = createCall;
var _request = require("../node/http/_request.cjs");
var _response = require("../node/http/_response.cjs");
function createCall(handle) {
return function callHandle(context) {
const req = new _request.IncomingMessage();
const res = new _response.ServerResponse(req);
req.url = context.url || "/";
req.method = context.method || "GET";
req.headers = {};
if (context.headers) {
const headerEntries = typeof context.headers.entries === "function" ? context.headers.entries() : Object.entries(context.headers);
for (const [name, value] of headerEntries) {
if (!value) {
continue;
}
req.headers[name.toLowerCase()] = value;
}
}
req.headers.host = req.headers.host || context.host || "localhost";
req.connection.encrypted = req.connection.encrypted || context.protocol === "https";
req.body = context.body || null;
return handle(req, res).then(() => {
const r = {
body: res._data || "",
headers: res._headers,
status: res.statusCode,
statusText: res.statusMessage
};
req.destroy();
res.destroy();
return r;
});
};
}

20
node_modules/unenv/runtime/fetch/call.d.ts generated vendored Normal file
View File

@@ -0,0 +1,20 @@
import { IncomingMessage } from "../node/http/_request";
import { ServerResponse } from "../node/http/_response";
export declare type Handle = (req: IncomingMessage, res: ServerResponse) => Promise<any>;
export declare type CallHandle = ReturnType<typeof createCall>;
export interface CallContext {
[key: string]: any;
url?: string;
method?: string;
headers?: Headers | {
[key: string]: string | string[];
};
protocol?: string;
body?: any;
}
export declare function createCall(handle: Handle): (context: CallContext) => Promise<{
body: BodyInit;
headers: import("../_internal/types").HeadersObject;
status: number;
statusText: string;
}>;

34
node_modules/unenv/runtime/fetch/call.mjs generated vendored Normal file
View File

@@ -0,0 +1,34 @@
import { IncomingMessage } from "../node/http/_request.mjs";
import { ServerResponse } from "../node/http/_response.mjs";
export function createCall(handle) {
return function callHandle(context) {
const req = new IncomingMessage();
const res = new ServerResponse(req);
req.url = context.url || "/";
req.method = context.method || "GET";
req.headers = {};
if (context.headers) {
const headerEntries = typeof context.headers.entries === "function" ? context.headers.entries() : Object.entries(context.headers);
for (const [name, value] of headerEntries) {
if (!value) {
continue;
}
req.headers[name.toLowerCase()] = value;
}
}
req.headers.host = req.headers.host || context.host || "localhost";
req.connection.encrypted = req.connection.encrypted || context.protocol === "https";
req.body = context.body || null;
return handle(req, res).then(() => {
const r = {
body: res._data || "",
headers: res._headers,
status: res.statusCode,
statusText: res.statusMessage
};
req.destroy();
res.destroy();
return r;
});
};
}

50
node_modules/unenv/runtime/fetch/index.cjs generated vendored Normal file
View File

@@ -0,0 +1,50 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
var _exportNames = {
createFetch: true
};
exports.createFetch = createFetch;
var _call = require("./call.cjs");
Object.keys(_call).forEach(function (key) {
if (key === "default" || key === "__esModule") return;
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
if (key in exports && exports[key] === _call[key]) return;
Object.defineProperty(exports, key, {
enumerable: true,
get: function () {
return _call[key];
}
});
});
function createFetch(call, _fetch = global.fetch) {
return async function ufetch(input, init) {
const url = input.toString();
if (!url.startsWith("/")) {
return _fetch(url, init);
}
try {
const r = await call({
url,
...init
});
return new Response(r.body, {
status: r.status,
statusText: r.statusText,
headers: Object.fromEntries(Object.entries(r.headers).map(([name, value]) => [name, Array.isArray(value) ? value.join(",") : value || ""]))
});
} catch (error) {
return new Response(error.toString(), {
status: Number.parseInt(error.statusCode || error.code) || 500,
statusText: error.statusText
});
}
};
}

4
node_modules/unenv/runtime/fetch/index.d.ts generated vendored Normal file
View File

@@ -0,0 +1,4 @@
import { CallContext, CallHandle } from "./call";
export * from "./call";
export declare type FetchOptions = globalThis.RequestInit & CallContext;
export declare function createFetch(call: CallHandle, _fetch?: typeof fetch): (input: string | Request, init: FetchOptions) => Promise<Response>;

26
node_modules/unenv/runtime/fetch/index.mjs generated vendored Normal file
View File

@@ -0,0 +1,26 @@
export * from "./call.mjs";
export function createFetch(call, _fetch = global.fetch) {
return async function ufetch(input, init) {
const url = input.toString();
if (!url.startsWith("/")) {
return _fetch(url, init);
}
try {
const r = await call({ url, ...init });
return new Response(r.body, {
status: r.status,
statusText: r.statusText,
headers: Object.fromEntries(
Object.entries(r.headers).map(
([name, value]) => [name, Array.isArray(value) ? value.join(",") : value || ""]
)
)
});
} catch (error) {
return new Response(error.toString(), {
status: Number.parseInt(error.statusCode || error.code) || 500,
statusText: error.statusText
});
}
};
}