🎉 initiate project *astro_rewrite*
This commit is contained in:
parent
ffd4d5e86c
commit
2ba37bfbe3
8658 changed files with 2268794 additions and 2538 deletions
73
node_modules/astro/dist/core/cookies/cookies.d.ts
generated
vendored
Normal file
73
node_modules/astro/dist/core/cookies/cookies.d.ts
generated
vendored
Normal file
|
@ -0,0 +1,73 @@
|
|||
interface AstroCookieSetOptions {
|
||||
domain?: string;
|
||||
expires?: Date;
|
||||
httpOnly?: boolean;
|
||||
maxAge?: number;
|
||||
path?: string;
|
||||
sameSite?: boolean | 'lax' | 'none' | 'strict';
|
||||
secure?: boolean;
|
||||
}
|
||||
type AstroCookieDeleteOptions = Pick<AstroCookieSetOptions, 'domain' | 'path'>;
|
||||
interface AstroCookieInterface {
|
||||
value: string | undefined;
|
||||
json(): Record<string, any>;
|
||||
number(): number;
|
||||
boolean(): boolean;
|
||||
}
|
||||
interface AstroCookiesInterface {
|
||||
get(key: string): AstroCookieInterface;
|
||||
has(key: string): boolean;
|
||||
set(key: string, value: string | number | boolean | Record<string, any>, options?: AstroCookieSetOptions): void;
|
||||
delete(key: string, options?: AstroCookieDeleteOptions): void;
|
||||
}
|
||||
declare class AstroCookie implements AstroCookieInterface {
|
||||
value: string | undefined;
|
||||
constructor(value: string | undefined);
|
||||
json(): any;
|
||||
number(): number;
|
||||
boolean(): boolean;
|
||||
}
|
||||
declare class AstroCookies implements AstroCookiesInterface {
|
||||
#private;
|
||||
constructor(request: Request);
|
||||
/**
|
||||
* Astro.cookies.delete(key) is used to delete a cookie. Using this method will result
|
||||
* in a Set-Cookie header added to the response.
|
||||
* @param key The cookie to delete
|
||||
* @param options Options related to this deletion, such as the path of the cookie.
|
||||
*/
|
||||
delete(key: string, options?: AstroCookieDeleteOptions): void;
|
||||
/**
|
||||
* Astro.cookies.get(key) is used to get a cookie value. The cookie value is read from the
|
||||
* request. If you have set a cookie via Astro.cookies.set(key, value), the value will be taken
|
||||
* from that set call, overriding any values already part of the request.
|
||||
* @param key The cookie to get.
|
||||
* @returns An object containing the cookie value as well as convenience methods for converting its value.
|
||||
*/
|
||||
get(key: string): AstroCookie;
|
||||
/**
|
||||
* 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.
|
||||
* @returns
|
||||
*/
|
||||
has(key: string): 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
|
||||
* can provide options customizing how this cookie will be set, such as setting httpOnly
|
||||
* in order to prevent the cookie from being read in client-side JavaScript.
|
||||
* @param key The name of the cookie to set.
|
||||
* @param value A value, either a string or other primitive or an object.
|
||||
* @param options Options for the cookie, such as the path and security settings.
|
||||
*/
|
||||
set(key: string, value: string | Record<string, any>, options?: AstroCookieSetOptions): void;
|
||||
/**
|
||||
* Astro.cookies.header() returns an iterator for the cookies that have previously
|
||||
* been set by either Astro.cookies.set() or Astro.cookies.delete().
|
||||
* This method is primarily used by adapters to set the header on outgoing responses.
|
||||
* @returns
|
||||
*/
|
||||
headers(): Generator<string, void, unknown>;
|
||||
}
|
||||
export { AstroCookies };
|
168
node_modules/astro/dist/core/cookies/cookies.js
generated
vendored
Normal file
168
node_modules/astro/dist/core/cookies/cookies.js
generated
vendored
Normal file
|
@ -0,0 +1,168 @@
|
|||
import { parse, serialize } from "cookie";
|
||||
import { AstroError, AstroErrorData } from "../errors/index.js";
|
||||
const DELETED_EXPIRATION = /* @__PURE__ */ new Date(0);
|
||||
const DELETED_VALUE = "deleted";
|
||||
const responseSentSymbol = Symbol.for("astro.responseSent");
|
||||
class AstroCookie {
|
||||
constructor(value) {
|
||||
this.value = value;
|
||||
}
|
||||
json() {
|
||||
if (this.value === void 0) {
|
||||
throw new Error(`Cannot convert undefined to an object.`);
|
||||
}
|
||||
return JSON.parse(this.value);
|
||||
}
|
||||
number() {
|
||||
return Number(this.value);
|
||||
}
|
||||
boolean() {
|
||||
if (this.value === "false")
|
||||
return false;
|
||||
if (this.value === "0")
|
||||
return false;
|
||||
return Boolean(this.value);
|
||||
}
|
||||
}
|
||||
class AstroCookies {
|
||||
#request;
|
||||
#requestValues;
|
||||
#outgoing;
|
||||
constructor(request) {
|
||||
this.#request = request;
|
||||
this.#requestValues = null;
|
||||
this.#outgoing = null;
|
||||
}
|
||||
/**
|
||||
* Astro.cookies.delete(key) is used to delete a cookie. Using this method will result
|
||||
* in a Set-Cookie header added to the response.
|
||||
* @param key The cookie to delete
|
||||
* @param options Options related to this deletion, such as the path of the cookie.
|
||||
*/
|
||||
delete(key, options) {
|
||||
const serializeOptions = {
|
||||
expires: DELETED_EXPIRATION
|
||||
};
|
||||
if (options == null ? void 0 : options.domain) {
|
||||
serializeOptions.domain = options.domain;
|
||||
}
|
||||
if (options == null ? void 0 : options.path) {
|
||||
serializeOptions.path = options.path;
|
||||
}
|
||||
this.#ensureOutgoingMap().set(key, [
|
||||
DELETED_VALUE,
|
||||
serialize(key, DELETED_VALUE, serializeOptions),
|
||||
false
|
||||
]);
|
||||
}
|
||||
/**
|
||||
* Astro.cookies.get(key) is used to get a cookie value. The cookie value is read from the
|
||||
* request. If you have set a cookie via Astro.cookies.set(key, value), the value will be taken
|
||||
* from that set call, overriding any values already part of the request.
|
||||
* @param key The cookie to get.
|
||||
* @returns An object containing the cookie value as well as convenience methods for converting its value.
|
||||
*/
|
||||
get(key) {
|
||||
var _a;
|
||||
if ((_a = this.#outgoing) == null ? void 0 : _a.has(key)) {
|
||||
let [serializedValue, , isSetValue] = this.#outgoing.get(key);
|
||||
if (isSetValue) {
|
||||
return new AstroCookie(serializedValue);
|
||||
} else {
|
||||
return new AstroCookie(void 0);
|
||||
}
|
||||
}
|
||||
const values = this.#ensureParsed();
|
||||
const value = values[key];
|
||||
return new AstroCookie(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.
|
||||
* @returns
|
||||
*/
|
||||
has(key) {
|
||||
var _a;
|
||||
if ((_a = this.#outgoing) == null ? void 0 : _a.has(key)) {
|
||||
let [, , isSetValue] = this.#outgoing.get(key);
|
||||
return isSetValue;
|
||||
}
|
||||
const values = this.#ensureParsed();
|
||||
return !!values[key];
|
||||
}
|
||||
/**
|
||||
* 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
|
||||
* can provide options customizing how this cookie will be set, such as setting httpOnly
|
||||
* in order to prevent the cookie from being read in client-side JavaScript.
|
||||
* @param key The name of the cookie to set.
|
||||
* @param value A value, either a string or other primitive or an object.
|
||||
* @param options Options for the cookie, such as the path and security settings.
|
||||
*/
|
||||
set(key, value, options) {
|
||||
let serializedValue;
|
||||
if (typeof value === "string") {
|
||||
serializedValue = value;
|
||||
} else {
|
||||
let toStringValue = value.toString();
|
||||
if (toStringValue === Object.prototype.toString.call(value)) {
|
||||
serializedValue = JSON.stringify(value);
|
||||
} else {
|
||||
serializedValue = toStringValue;
|
||||
}
|
||||
}
|
||||
const serializeOptions = {};
|
||||
if (options) {
|
||||
Object.assign(serializeOptions, options);
|
||||
}
|
||||
this.#ensureOutgoingMap().set(key, [
|
||||
serializedValue,
|
||||
serialize(key, serializedValue, serializeOptions),
|
||||
true
|
||||
]);
|
||||
if (this.#request[responseSentSymbol]) {
|
||||
throw new AstroError({
|
||||
...AstroErrorData.ResponseSentError
|
||||
});
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Astro.cookies.header() returns an iterator for the cookies that have previously
|
||||
* been set by either Astro.cookies.set() or Astro.cookies.delete().
|
||||
* This method is primarily used by adapters to set the header on outgoing responses.
|
||||
* @returns
|
||||
*/
|
||||
*headers() {
|
||||
if (this.#outgoing == null)
|
||||
return;
|
||||
for (const [, value] of this.#outgoing) {
|
||||
yield value[1];
|
||||
}
|
||||
}
|
||||
#ensureParsed() {
|
||||
if (!this.#requestValues) {
|
||||
this.#parse();
|
||||
}
|
||||
if (!this.#requestValues) {
|
||||
this.#requestValues = {};
|
||||
}
|
||||
return this.#requestValues;
|
||||
}
|
||||
#ensureOutgoingMap() {
|
||||
if (!this.#outgoing) {
|
||||
this.#outgoing = /* @__PURE__ */ new Map();
|
||||
}
|
||||
return this.#outgoing;
|
||||
}
|
||||
#parse() {
|
||||
const raw = this.#request.headers.get("cookie");
|
||||
if (!raw) {
|
||||
return;
|
||||
}
|
||||
this.#requestValues = parse(raw);
|
||||
}
|
||||
}
|
||||
export {
|
||||
AstroCookies
|
||||
};
|
2
node_modules/astro/dist/core/cookies/index.d.ts
generated
vendored
Normal file
2
node_modules/astro/dist/core/cookies/index.d.ts
generated
vendored
Normal file
|
@ -0,0 +1,2 @@
|
|||
export { AstroCookies } from './cookies.js';
|
||||
export { attachToResponse, getSetCookiesFromResponse } from './response.js';
|
7
node_modules/astro/dist/core/cookies/index.js
generated
vendored
Normal file
7
node_modules/astro/dist/core/cookies/index.js
generated
vendored
Normal file
|
@ -0,0 +1,7 @@
|
|||
import { AstroCookies } from "./cookies.js";
|
||||
import { attachToResponse, getSetCookiesFromResponse } from "./response.js";
|
||||
export {
|
||||
AstroCookies,
|
||||
attachToResponse,
|
||||
getSetCookiesFromResponse
|
||||
};
|
3
node_modules/astro/dist/core/cookies/response.d.ts
generated
vendored
Normal file
3
node_modules/astro/dist/core/cookies/response.d.ts
generated
vendored
Normal file
|
@ -0,0 +1,3 @@
|
|||
import type { AstroCookies } from './cookies';
|
||||
export declare function attachToResponse(response: Response, cookies: AstroCookies): void;
|
||||
export declare function getSetCookiesFromResponse(response: Response): Generator<string, string[]>;
|
26
node_modules/astro/dist/core/cookies/response.js
generated
vendored
Normal file
26
node_modules/astro/dist/core/cookies/response.js
generated
vendored
Normal file
|
@ -0,0 +1,26 @@
|
|||
const astroCookiesSymbol = Symbol.for("astro.cookies");
|
||||
function attachToResponse(response, cookies) {
|
||||
Reflect.set(response, astroCookiesSymbol, cookies);
|
||||
}
|
||||
function getFromResponse(response) {
|
||||
let cookies = Reflect.get(response, astroCookiesSymbol);
|
||||
if (cookies != null) {
|
||||
return cookies;
|
||||
} else {
|
||||
return void 0;
|
||||
}
|
||||
}
|
||||
function* getSetCookiesFromResponse(response) {
|
||||
const cookies = getFromResponse(response);
|
||||
if (!cookies) {
|
||||
return [];
|
||||
}
|
||||
for (const headerValue of cookies.headers()) {
|
||||
yield headerValue;
|
||||
}
|
||||
return [];
|
||||
}
|
||||
export {
|
||||
attachToResponse,
|
||||
getSetCookiesFromResponse
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue