🎉 initiate project *astro_rewrite*

This commit is contained in:
sindrekjelsrud 2023-07-19 21:31:30 +02:00
parent ffd4d5e86c
commit 2ba37bfbe3
8658 changed files with 2268794 additions and 2538 deletions

11
node_modules/astro/dist/core/endpoint/dev/index.d.ts generated vendored Normal file
View file

@ -0,0 +1,11 @@
/// <reference types="node" />
import type { SSROptions } from '../../render/dev';
export declare function call(options: SSROptions): Promise<{
type: "simple";
body: string;
encoding?: BufferEncoding | undefined;
cookies: import("../../cookies/cookies").AstroCookies;
} | {
type: "response";
response: Response;
}>;

17
node_modules/astro/dist/core/endpoint/dev/index.js generated vendored Normal file
View file

@ -0,0 +1,17 @@
import { createRenderContext } from "../../render/index.js";
import { callEndpoint } from "../index.js";
async function call(options) {
const { env, preload, middleware } = options;
const endpointHandler = preload;
const ctx = await createRenderContext({
request: options.request,
pathname: options.pathname,
route: options.route,
env,
mod: preload
});
return await callEndpoint(endpointHandler, env, ctx, middleware == null ? void 0 : middleware.onRequest);
}
export {
call
};

29
node_modules/astro/dist/core/endpoint/index.d.ts generated vendored Normal file
View file

@ -0,0 +1,29 @@
/// <reference types="node" />
import type { APIContext, AstroConfig, EndpointHandler, EndpointOutput, MiddlewareHandler, Params } from '../../@types/astro';
import type { Environment, RenderContext } from '../render/index';
import { AstroCookies } from '../cookies/index.js';
type EndpointCallResult = {
type: 'simple';
body: string;
encoding?: BufferEncoding;
cookies: AstroCookies;
} | {
type: 'response';
response: Response;
};
type CreateAPIContext = {
request: Request;
params: Params;
site?: string;
props: Record<string, any>;
adapterName?: string;
};
/**
* Creates a context that holds all the information needed to handle an Astro endpoint.
*
* @param {CreateAPIContext} payload
*/
export declare function createAPIContext({ request, params, site, props, adapterName, }: CreateAPIContext): APIContext;
export declare function callEndpoint<MiddlewareResult = Response | EndpointOutput>(mod: EndpointHandler, env: Environment, ctx: RenderContext, onRequest?: MiddlewareHandler<MiddlewareResult> | undefined): Promise<EndpointCallResult>;
export declare function throwIfRedirectNotAllowed(response: Response, config: AstroConfig): void;
export {};

126
node_modules/astro/dist/core/endpoint/index.js generated vendored Normal file
View file

@ -0,0 +1,126 @@
import { isServerLikeOutput } from "../../prerender/utils.js";
import { renderEndpoint } from "../../runtime/server/index.js";
import { ASTRO_VERSION } from "../constants.js";
import { AstroCookies, attachToResponse } from "../cookies/index.js";
import { AstroError, AstroErrorData } from "../errors/index.js";
import { warn } from "../logger/core.js";
import { callMiddleware } from "../middleware/callMiddleware.js";
const clientAddressSymbol = Symbol.for("astro.clientAddress");
const clientLocalsSymbol = Symbol.for("astro.locals");
function createAPIContext({
request,
params,
site,
props,
adapterName
}) {
const context = {
cookies: new AstroCookies(request),
request,
params,
site: site ? new URL(site) : void 0,
generator: `Astro v${ASTRO_VERSION}`,
props,
redirect(path, status) {
return new Response(null, {
status: status || 302,
headers: {
Location: path
}
});
},
url: new URL(request.url),
get clientAddress() {
if (!(clientAddressSymbol in request)) {
if (adapterName) {
throw new AstroError({
...AstroErrorData.ClientAddressNotAvailable,
message: AstroErrorData.ClientAddressNotAvailable.message(adapterName)
});
} else {
throw new AstroError(AstroErrorData.StaticClientAddressNotAvailable);
}
}
return Reflect.get(request, clientAddressSymbol);
}
};
Object.defineProperty(context, "locals", {
enumerable: true,
get() {
return Reflect.get(request, clientLocalsSymbol);
},
set(val) {
if (typeof val !== "object") {
throw new AstroError(AstroErrorData.LocalsNotAnObject);
} else {
Reflect.set(request, clientLocalsSymbol, val);
}
}
});
return context;
}
async function callEndpoint(mod, env, ctx, onRequest) {
var _a;
const context = createAPIContext({
request: ctx.request,
params: ctx.params,
props: ctx.props,
site: env.site,
adapterName: env.adapterName
});
let response;
if (onRequest) {
response = await callMiddleware(
env.logging,
onRequest,
context,
async () => {
return await renderEndpoint(mod, context, env.ssr);
}
);
} else {
response = await renderEndpoint(mod, context, env.ssr);
}
if (response instanceof Response) {
attachToResponse(response, context.cookies);
return {
type: "response",
response
};
}
if (env.ssr && !((_a = ctx.route) == null ? void 0 : _a.prerender)) {
if (response.hasOwnProperty("headers")) {
warn(
env.logging,
"ssr",
"Setting headers is not supported when returning an object. Please return an instance of Response. See https://docs.astro.build/en/core-concepts/endpoints/#server-endpoints-api-routes for more information."
);
}
if (response.encoding) {
warn(
env.logging,
"ssr",
"`encoding` is ignored in SSR. To return a charset other than UTF-8, please return an instance of Response. See https://docs.astro.build/en/core-concepts/endpoints/#server-endpoints-api-routes for more information."
);
}
}
return {
type: "simple",
body: response.body,
encoding: response.encoding,
cookies: context.cookies
};
}
function isRedirect(statusCode) {
return statusCode >= 300 && statusCode < 400;
}
function throwIfRedirectNotAllowed(response, config) {
if (!isServerLikeOutput(config) && isRedirect(response.status) && !config.experimental.redirects) {
throw new AstroError(AstroErrorData.StaticRedirectNotAvailable);
}
}
export {
callEndpoint,
createAPIContext,
throwIfRedirectNotAllowed
};