full site update

This commit is contained in:
2025-07-24 18:46:24 +02:00
parent bfe2b90d8d
commit 37a6e0ab31
6912 changed files with 540482 additions and 361712 deletions

View File

@@ -1,5 +1,5 @@
import type { CookieSerializeOptions } from 'cookie';
export type AstroCookieSetOptions = Pick<CookieSerializeOptions, 'domain' | 'path' | 'expires' | 'maxAge' | 'httpOnly' | 'sameSite' | 'secure' | 'encode'>;
import type { SerializeOptions } from 'cookie';
export type AstroCookieSetOptions = Pick<SerializeOptions, 'domain' | 'path' | 'expires' | 'maxAge' | 'httpOnly' | 'sameSite' | 'secure' | 'encode'>;
export interface AstroCookieGetOptions {
decode?: (value: string) => string;
}
@@ -45,9 +45,10 @@ declare class AstroCookies implements AstroCookiesInterface {
* Astro.cookies.has(key) returns a boolean indicating whether this cookie is either
* part of the initial request or set via Astro.cookies.set(key)
* @param key The cookie to check for.
* @param _options This parameter is no longer used.
* @returns
*/
has(key: string, options?: AstroCookieGetOptions | undefined): boolean;
has(key: string, _options?: AstroCookieGetOptions): boolean;
/**
* Astro.cookies.set(key, value) is used to set a cookie's value. If provided
* an object it will be stringified via JSON.stringify(value). Additionally you

View File

@@ -3,6 +3,7 @@ import { AstroError, AstroErrorData } from "../errors/index.js";
const DELETED_EXPIRATION = /* @__PURE__ */ new Date(0);
const DELETED_VALUE = "deleted";
const responseSentSymbol = Symbol.for("astro.responseSent");
const identity = (value) => value;
class AstroCookie {
constructor(value) {
this.value = value;
@@ -73,25 +74,29 @@ class AstroCookies {
return void 0;
}
}
const values = this.#ensureParsed(options);
const decode = options?.decode ?? decodeURIComponent;
const values = this.#ensureParsed();
if (key in values) {
const value = values[key];
return new AstroCookie(value);
if (value) {
return new AstroCookie(decode(value));
}
}
}
/**
* Astro.cookies.has(key) returns a boolean indicating whether this cookie is either
* part of the initial request or set via Astro.cookies.set(key)
* @param key The cookie to check for.
* @param _options This parameter is no longer used.
* @returns
*/
has(key, options = void 0) {
has(key, _options) {
if (this.#outgoing?.has(key)) {
let [, , isSetValue] = this.#outgoing.get(key);
return isSetValue;
}
const values = this.#ensureParsed(options);
return !!values[key];
const values = this.#ensureParsed();
return values[key] !== void 0;
}
/**
* Astro.cookies.set(key, value) is used to set a cookie's value. If provided
@@ -168,9 +173,9 @@ class AstroCookies {
cookies.#consumed = true;
return cookies.headers();
}
#ensureParsed(options = void 0) {
#ensureParsed() {
if (!this.#requestValues) {
this.#parse(options);
this.#parse();
}
if (!this.#requestValues) {
this.#requestValues = {};
@@ -183,12 +188,12 @@ class AstroCookies {
}
return this.#outgoing;
}
#parse(options = void 0) {
#parse() {
const raw = this.#request.headers.get("cookie");
if (!raw) {
return;
}
this.#requestValues = parse(raw, options);
this.#requestValues = parse(raw, { decode: identity });
}
}
export {

View File

@@ -1,3 +1,3 @@
export type { AstroCookieGetOptions, AstroCookieSetOptions } from './cookies.js';
export { AstroCookies } from './cookies.js';
export { attachCookiesToResponse, getSetCookiesFromResponse, responseHasCookies, } from './response.js';
export type { AstroCookieSetOptions, AstroCookieGetOptions } from './cookies.js';
export { attachCookiesToResponse, getSetCookiesFromResponse, } from './response.js';

View File

@@ -1,12 +1,10 @@
import { AstroCookies } from "./cookies.js";
import {
attachCookiesToResponse,
getSetCookiesFromResponse,
responseHasCookies
getSetCookiesFromResponse
} from "./response.js";
export {
AstroCookies,
attachCookiesToResponse,
getSetCookiesFromResponse,
responseHasCookies
getSetCookiesFromResponse
};

View File

@@ -1,5 +1,4 @@
import { AstroCookies } from './cookies.js';
export declare function attachCookiesToResponse(response: Response, cookies: AstroCookies): void;
export declare function responseHasCookies(response: Response): boolean;
export declare function getCookiesFromResponse(response: Response): AstroCookies | undefined;
export declare function getSetCookiesFromResponse(response: Response): Generator<string, string[]>;

View File

@@ -3,9 +3,6 @@ const astroCookiesSymbol = Symbol.for("astro.cookies");
function attachCookiesToResponse(response, cookies) {
Reflect.set(response, astroCookiesSymbol, cookies);
}
function responseHasCookies(response) {
return Reflect.has(response, astroCookiesSymbol);
}
function getCookiesFromResponse(response) {
let cookies = Reflect.get(response, astroCookiesSymbol);
if (cookies != null) {
@@ -27,6 +24,5 @@ function* getSetCookiesFromResponse(response) {
export {
attachCookiesToResponse,
getCookiesFromResponse,
getSetCookiesFromResponse,
responseHasCookies
getSetCookiesFromResponse
};