[ci] format

This commit is contained in:
matthewp 2022-09-28 20:57:35 +00:00 committed by fredkbot
parent d3091f89e9
commit 55a1b5bb58
23 changed files with 127 additions and 137 deletions

View file

@ -14,8 +14,8 @@ import type * as vite from 'vite';
import type { z } from 'zod';
import type { SerializedSSRManifest } from '../core/app/types';
import type { PageBuildData } from '../core/build/types';
import type { AstroCookies } from '../core/cookies';
import type { AstroConfigSchema } from '../core/config';
import type { AstroCookies } from '../core/cookies';
import type { ViteConfigWithSSR } from '../core/create-vite';
import type { AstroComponentFactory, Metadata } from '../runtime/server';
export type {
@ -120,7 +120,7 @@ export interface AstroGlobal extends AstroGlobalPartial {
/**
* Utility for getting and setting cookies values.
*/
cookies: AstroCookies,
cookies: AstroCookies;
url: URL;
/** Parameters passed to a dynamic page generated using [getStaticPaths](https://docs.astro.build/en/reference/api-reference/#getstaticpaths)
*

View file

@ -9,6 +9,7 @@ import type { LogOptions } from '../logger/core.js';
import type { RouteInfo, SSRManifest as Manifest } from './types';
import mime from 'mime';
import { getSetCookiesFromResponse } from '../cookies/index.js';
import { call as callEndpoint } from '../endpoint/index.js';
import { consoleLogDestination } from '../logger/console.js';
import { error } from '../logger/core.js';
@ -21,7 +22,6 @@ import {
} from '../render/ssr-element.js';
import { matchRoute } from '../routing/match.js';
export { deserializeManifest } from './common.js';
import { getSetCookiesFromResponse } from '../cookies/index.js';
export const pagesVirtualModuleId = '@astrojs-pages-virtual-entry';
export const resolvedPagesVirtualModuleId = '\0' + pagesVirtualModuleId;

View file

@ -68,7 +68,7 @@ class AstroCookies implements AstroCookiesInterface {
*/
delete(key: string, options?: AstroCookieDeleteOptions): void {
const serializeOptions: CookieSerializeOptions = {
expires: DELETED_EXPIRATION
expires: DELETED_EXPIRATION,
};
if (options?.path) {
@ -79,7 +79,7 @@ class AstroCookies implements AstroCookiesInterface {
this.#ensureOutgoingMap().set(key, [
DELETED_VALUE,
serialize(key, DELETED_VALUE, serializeOptions),
false
false,
]);
}
@ -153,7 +153,7 @@ class AstroCookies implements AstroCookiesInterface {
this.#ensureOutgoingMap().set(key, [
serializedValue,
serialize(key, serializedValue, serializeOptions),
true
true,
]);
}
@ -197,6 +197,4 @@ class AstroCookies implements AstroCookiesInterface {
}
}
export {
AstroCookies
};
export { AstroCookies };

View file

@ -1,9 +1,2 @@
export {
AstroCookies
} from './cookies.js';
export {
attachToResponse,
getSetCookiesFromResponse
} from './response.js';
export { AstroCookies } from './cookies.js';
export { attachToResponse, getSetCookiesFromResponse } from './response.js';

View file

@ -1,8 +1,8 @@
import type { APIContext, EndpointHandler, Params } from '../../@types/astro';
import type { RenderOptions } from '../render/core';
import { AstroCookies, attachToResponse } from '../cookies/index.js';
import { renderEndpoint } from '../../runtime/server/index.js';
import { AstroCookies, attachToResponse } from '../cookies/index.js';
import { getParamsAndProps, GetParamsAndPropsError } from '../render/core.js';
export type EndpointOptions = Pick<
@ -34,7 +34,7 @@ function createAPIContext(request: Request, params: Params): APIContext {
return {
cookies: new AstroCookies(request),
request,
params
params,
};
}

View file

@ -10,8 +10,8 @@ import type {
} from '../../@types/astro';
import type { LogOptions } from '../logger/core.js';
import { attachToResponse } from '../cookies/index.js';
import { Fragment, renderPage } from '../../runtime/server/index.js';
import { attachToResponse } from '../cookies/index.js';
import { getParams } from '../routing/params.js';
import { createResult } from './result.js';
import { callGetStaticPaths, findPathItemByKey, RouteCache } from './route-cache.js';

View file

@ -5,8 +5,8 @@ import type { AstroSettings, ManifestData } from '../@types/astro';
import type { SSROptions } from '../core/render/dev/index';
import { Readable } from 'stream';
import { call as callEndpoint } from '../core/endpoint/dev/index.js';
import { getSetCookiesFromResponse } from '../core/cookies/index.js';
import { call as callEndpoint } from '../core/endpoint/dev/index.js';
import {
collectErrorMetadata,
ErrorWithMetadata,

View file

@ -30,8 +30,8 @@ describe('Astro.cookies', () => {
it('is able to get cookies from the request', async () => {
const response = await fixture.fetch('/get-json', {
headers: {
cookie: `prefs=${encodeURIComponent(JSON.stringify({ mode: 'light' }))}`
}
cookie: `prefs=${encodeURIComponent(JSON.stringify({ mode: 'light' }))}`,
},
});
expect(response.status).to.equal(200);
const html = await response.text();
@ -42,7 +42,7 @@ describe('Astro.cookies', () => {
it('can set the cookie value', async () => {
const response = await fixture.fetch('/set-value', {
method: 'POST'
method: 'POST',
});
expect(response.status).to.equal(200);
expect(response.headers.has('set-cookie')).to.equal(true);
@ -65,8 +65,8 @@ describe('Astro.cookies', () => {
it('is able to get cookies from the request', async () => {
const response = await fetchResponse('/get-json', {
headers: {
cookie: `prefs=${encodeURIComponent(JSON.stringify({ mode: 'light' }))}`
}
cookie: `prefs=${encodeURIComponent(JSON.stringify({ mode: 'light' }))}`,
},
});
expect(response.status).to.equal(200);
const html = await response.text();
@ -77,7 +77,7 @@ describe('Astro.cookies', () => {
it('can set the cookie value', async () => {
const response = await fetchResponse('/set-value', {
method: 'POST'
method: 'POST',
});
expect(response.status).to.equal(200);
let headers = Array.from(app.setCookieHeaders(response));
@ -88,8 +88,8 @@ describe('Astro.cookies', () => {
it('Early returning a Response still includes set headers', async () => {
const response = await fetchResponse('/early-return', {
headers: {
cookie: `prefs=${encodeURIComponent(JSON.stringify({ mode: 'light' }))}`
}
cookie: `prefs=${encodeURIComponent(JSON.stringify({ mode: 'light' }))}`,
},
});
expect(response.status).to.equal(302);
let headers = Array.from(app.setCookieHeaders(response));
@ -104,8 +104,8 @@ describe('Astro.cookies', () => {
const response = await fetchResponse('/set-prefs', {
method: 'POST',
headers: {
cookie: `prefs=${encodeURIComponent(JSON.stringify({ mode: 'light' }))}`
}
cookie: `prefs=${encodeURIComponent(JSON.stringify({ mode: 'light' }))}`,
},
});
expect(response.status).to.equal(302);
let headers = Array.from(app.setCookieHeaders(response));
@ -115,5 +115,5 @@ describe('Astro.cookies', () => {
expect(data).to.be.an('object');
expect(data.mode).to.equal('dark');
});
})
});
});

View file

@ -9,8 +9,8 @@ describe('astro/src/core/cookies', () => {
it('creates a Set-Cookie header to delete it', () => {
let req = new Request('http://example.com/', {
headers: {
'cookie': 'foo=bar'
}
cookie: 'foo=bar',
},
});
let cookies = new AstroCookies(req);
expect(cookies.get('foo').value).to.equal('bar');
@ -23,8 +23,8 @@ describe('astro/src/core/cookies', () => {
it('calling cookies.get() after returns undefined', () => {
let req = new Request('http://example.com/', {
headers: {
'cookie': 'foo=bar'
}
cookie: 'foo=bar',
},
});
let cookies = new AstroCookies(req);
expect(cookies.get('foo').value).to.equal('bar');
@ -36,8 +36,8 @@ describe('astro/src/core/cookies', () => {
it('calling cookies.has() after returns false', () => {
let req = new Request('http://example.com/', {
headers: {
'cookie': 'foo=bar'
}
cookie: 'foo=bar',
},
});
let cookies = new AstroCookies(req);
expect(cookies.has('foo')).to.equal(true);
@ -50,7 +50,7 @@ describe('astro/src/core/cookies', () => {
let req = new Request('http://example.com/');
let cookies = new AstroCookies(req);
cookies.delete('foo', {
path: '/subpath/'
path: '/subpath/',
});
let headers = Array.from(cookies.headers());
expect(headers).to.have.a.lengthOf(1);

View file

@ -9,8 +9,8 @@ describe('astro/src/core/cookies', () => {
it('gets the cookie value', () => {
const req = new Request('http://example.com/', {
headers: {
'cookie': 'foo=bar'
}
cookie: 'foo=bar',
},
});
const cookies = new AstroCookies(req);
expect(cookies.get('foo').value).to.equal('bar');
@ -20,8 +20,8 @@ describe('astro/src/core/cookies', () => {
it('returns a JavaScript object', () => {
const req = new Request('http://example.com/', {
headers: {
'cookie': 'foo=%7B%22key%22%3A%22value%22%7D'
}
cookie: 'foo=%7B%22key%22%3A%22value%22%7D',
},
});
let cookies = new AstroCookies(req);
@ -42,8 +42,8 @@ describe('astro/src/core/cookies', () => {
it('Coerces into a number', () => {
const req = new Request('http://example.com/', {
headers: {
'cookie': 'foo=22'
}
cookie: 'foo=22',
},
});
let cookies = new AstroCookies(req);
@ -55,8 +55,8 @@ describe('astro/src/core/cookies', () => {
it('Coerces non-number into NaN', () => {
const req = new Request('http://example.com/', {
headers: {
'cookie': 'foo=bar'
}
cookie: 'foo=bar',
},
});
let cookies = new AstroCookies(req);
@ -70,8 +70,8 @@ describe('astro/src/core/cookies', () => {
it('Coerces true into `true`', () => {
const req = new Request('http://example.com/', {
headers: {
'cookie': 'foo=true'
}
cookie: 'foo=true',
},
});
let cookies = new AstroCookies(req);
@ -83,8 +83,8 @@ describe('astro/src/core/cookies', () => {
it('Coerces false into `false`', () => {
const req = new Request('http://example.com/', {
headers: {
'cookie': 'foo=false'
}
cookie: 'foo=false',
},
});
let cookies = new AstroCookies(req);
@ -96,8 +96,8 @@ describe('astro/src/core/cookies', () => {
it('Coerces 1 into `true`', () => {
const req = new Request('http://example.com/', {
headers: {
'cookie': 'foo=1'
}
cookie: 'foo=1',
},
});
let cookies = new AstroCookies(req);
@ -109,8 +109,8 @@ describe('astro/src/core/cookies', () => {
it('Coerces 0 into `false`', () => {
const req = new Request('http://example.com/', {
headers: {
'cookie': 'foo=0'
}
cookie: 'foo=0',
},
});
let cookies = new AstroCookies(req);
@ -122,8 +122,8 @@ describe('astro/src/core/cookies', () => {
it('Coerces truthy strings into `true`', () => {
const req = new Request('http://example.com/', {
headers: {
'cookie': 'foo=bar'
}
cookie: 'foo=bar',
},
});
let cookies = new AstroCookies(req);

View file

@ -9,8 +9,8 @@ describe('astro/src/core/cookies', () => {
it('returns true if the request has the cookie', () => {
let req = new Request('http://example.com/', {
headers: {
'cookie': 'foo=bar'
}
cookie: 'foo=bar',
},
});
let cookies = new AstroCookies(req);
expect(cookies.has('foo')).to.equal(true);

View file

@ -20,7 +20,7 @@ describe('astro/src/core/cookies', () => {
let cookies = new AstroCookies(req);
cookies.set('foo', 'bar', {
httpOnly: true,
path: '/subpath/'
path: '/subpath/',
});
let headers = Array.from(cookies.headers());
expect(headers).to.have.a.lengthOf(1);
@ -68,8 +68,8 @@ describe('astro/src/core/cookies', () => {
it('Overrides a value in the request', () => {
let req = new Request('http://example.com/', {
headers: {
'cookie': 'foo=bar'
}
cookie: 'foo=bar',
},
});
let cookies = new AstroCookies(req);
expect(cookies.get('foo').value).to.equal('bar');

View file

@ -111,12 +111,7 @@ class SquooshService extends BaseSSRService {
throw new Error(`Unknown image output: "${transform.format}" used for ${transform.src}`);
}
const data = await processBuffer(
inputBuffer,
operations,
transform.format,
transform.quality
);
const data = await processBuffer(inputBuffer, operations, transform.format, transform.quality);
return {
data: Buffer.from(data),

View file

@ -1,5 +1,5 @@
import type { IncomingMessage, ServerResponse } from 'node:http';
import type { App } from 'astro/app';
import type { IncomingMessage, ServerResponse } from 'node:http';
import { Readable } from 'node:stream';
const clientAddressSymbol = Symbol.for('astro.clientAddress');
@ -78,7 +78,11 @@ export async function getRequest(base: string, req: IncomingMessage): Promise<Re
return request;
}
export async function setResponse(app: App, res: ServerResponse, response: Response): Promise<void> {
export async function setResponse(
app: App,
res: ServerResponse,
response: Response
): Promise<void> {
const headers = Object.fromEntries(response.headers);
if (response.headers.has('set-cookie')) {