site: fix svelte-check errors (#8696)

pull/8705/head
Ben McCann 1 year ago committed by GitHub
parent 276d2f86ba
commit 53b8158fc5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -11,8 +11,8 @@
"update": "node scripts/update.js --force=true", "update": "node scripts/update.js --force=true",
"preview": "vite preview", "preview": "vite preview",
"start": "node build", "start": "node build",
"check": "svelte-kit sync && svelte-check --tsconfig ./jsconfig.json", "check": "node scripts/update.js && svelte-kit sync && svelte-check",
"check:watch": "svelte-kit sync && svelte-check --tsconfig ./jsconfig.json --watch", "check:watch": "svelte-kit sync && svelte-check --watch",
"format": "pnpm run check:format -- --write", "format": "pnpm run check:format -- --write",
"check:format": "prettier --check . --ignore-path .gitignore --plugin-search-dir=." "check:format": "prettier --check . --ignore-path .gitignore --plugin-search-dir=."
}, },

@ -1,10 +1,14 @@
import { client } from './client.js'; import { client } from './client.js';
/** @typedef {import('./types').User} User */
/** @typedef {import('./types').UserID} UserID */ /** @typedef {import('./types').UserID} UserID */
/** @typedef {import('./types').Gist} Gist */ /** @typedef {import('./types').Gist} Gist */
const PAGE_SIZE = 90; const PAGE_SIZE = 90;
/**
* @param {User} user
*/
export async function list(user, { offset, search }) { export async function list(user, { offset, search }) {
const { data, error } = await client.rpc('gist_list', { const { data, error } = await client.rpc('gist_list', {
list_search: search || '', list_search: search || '',
@ -47,7 +51,7 @@ export async function create(user, gist) {
/** /**
* @param {string} id * @param {string} id
* @returns {Promise<Gist>} * @returns {Promise<Partial<Gist>>}
*/ */
export async function read(id) { export async function read(id) {
const { data, error } = await client const { data, error } = await client

@ -2,15 +2,17 @@ import * as cookie from 'cookie';
import flru from 'flru'; import flru from 'flru';
import { client } from './client.js'; import { client } from './client.js';
const session_cache = flru(1000);
/** @typedef {import('./types').User} User */ /** @typedef {import('./types').User} User */
/** /**
* @param {User} user * @type {import('flru').flruCache<User>}
* @param {string} access_token
*/ */
export async function create(user, access_token) { const session_cache = flru(1000);
/**
* @param {import('./types').GitHubUser} user
*/
export async function create(user) {
const { data, error } = await client.rpc('login', { const { data, error } = await client.rpc('login', {
user_github_id: user.github_id, user_github_id: user.github_id,
user_github_name: user.github_name, user_github_name: user.github_name,
@ -45,22 +47,20 @@ export async function read(sessionid) {
if (!session_cache.get(sessionid)) { if (!session_cache.get(sessionid)) {
session_cache.set( session_cache.set(
sessionid, sessionid,
client await client
.rpc('get_user', { sessionid }) .rpc('get_user', { sessionid })
.then(({ data, error }) => { .then(({ data, error }) => {
if (error) { if (error) {
session_cache.set(sessionid, null);
throw new Error(error.message); throw new Error(error.message);
} }
return data.id && data; return data.id && data;
}) })
.catch(() => {
session_cache.set(sessionid, null);
})
); );
} }
return await session_cache.get(sessionid); return session_cache.get(sessionid);
} }
/** @param {string} sessionid */ /** @param {string} sessionid */
@ -74,7 +74,7 @@ export async function destroy(sessionid) {
session_cache.set(sessionid, null); session_cache.set(sessionid, null);
} }
/** @type {string | null} str */ /** @param {string | null} str */
export function from_cookie(str) { export function from_cookie(str) {
if (!str) return null; if (!str) return null;
return read(cookie.parse(str).sid); return read(cookie.parse(str).sid);

@ -2,9 +2,16 @@ export type UserID = number;
export interface User { export interface User {
id: UserID; id: UserID;
name: string; github_name: string;
username: string; github_login: string;
avatar: string; github_avatar_url: string;
}
export interface GitHubUser {
github_id: string;
github_name: string;
github_login: string;
github_avatar_url: string;
} }
export interface Gist { export interface Gist {

@ -1,5 +1,5 @@
<script> <script>
import { invalidate } from '$app/navigation'; import { invalidateAll } from '$app/navigation';
import { setContext } from 'svelte'; import { setContext } from 'svelte';
setContext('app', { setContext('app', {
@ -13,13 +13,13 @@
window.addEventListener('message', function handler(event) { window.addEventListener('message', function handler(event) {
login_window.close(); login_window.close();
window.removeEventListener('message', handler); window.removeEventListener('message', handler);
invalidate(); invalidateAll();
}); });
}, },
logout: async () => { logout: async () => {
const r = await fetch(`/auth/logout`); const r = await fetch(`/auth/logout`);
if (r.ok) invalidate(); if (r.ok) invalidateAll();
} }
}); });
</script> </script>

@ -2,14 +2,14 @@
import { getContext } from 'svelte'; import { getContext } from 'svelte';
import { Icon } from '@sveltejs/site-kit/components'; import { Icon } from '@sveltejs/site-kit/components';
import { ago } from '$lib/time'; import { ago } from '$lib/time';
import { goto, invalidate } from '$app/navigation'; import { goto, invalidateAll } from '$app/navigation';
/** @type {import('./$types').PageData} */ /** @type {import('./$types').PageData} */
export let data; export let data;
const { login, logout } = getContext('app'); const { login, logout } = getContext('app');
const format = (str) => ago(new Date(str)); const format = /** @param {string} str */ (str) => ago(new Date(str));
let destroying = false; let destroying = false;
@ -35,7 +35,7 @@
if (res.ok) { if (res.ok) {
selected = []; selected = [];
await invalidate(); await invalidateAll();
// this is a temporary fix because invalidation only works once // this is a temporary fix because invalidation only works once
// TODO raise an issue // TODO raise an issue
@ -84,8 +84,8 @@
{:else} {:else}
<form <form
on:submit|preventDefault={(e) => { on:submit|preventDefault={(e) => {
const search = new FormData(e.target).get('search'); const search = new FormData(/** @type {HTMLFormElement} */ (e.target)).get('search');
goto(search ? `/apps?search=${encodeURIComponent(search)}` : '/apps'); goto(search ? `/apps?search=${encodeURIComponent(search.toString())}` : '/apps');
}} }}
> >
<input <input

@ -36,7 +36,7 @@ export async function GET({ url }) {
github_avatar_url: profile.avatar_url github_avatar_url: profile.avatar_url
}; };
const { sessionid, expires } = await session.create(user, access_token); const { sessionid, expires } = await session.create(user);
return new Response( return new Response(
` `

@ -1,7 +1,7 @@
import * as cookie from 'cookie'; import * as cookie from 'cookie';
import * as session from '$lib/db/session'; import * as session from '$lib/db/session';
export async function GET({ request }) { export async function GET({ request, url }) {
const cookies = cookie.parse(request.headers.get('cookie') || ''); const cookies = cookie.parse(request.headers.get('cookie') || '');
await session.destroy(cookies.sid); await session.destroy(cookies.sid);
@ -11,7 +11,7 @@ export async function GET({ request }) {
maxAge: -1, maxAge: -1,
path: '/', path: '/',
httpOnly: true, httpOnly: true,
secure: request.url.protocol === 'https' secure: url.protocol === 'https'
}) })
} }
}); });

@ -1,6 +1,6 @@
import { redirect } from '@sveltejs/kit'; import { redirect } from '@sveltejs/kit';
export function load({ event }) { export function load() {
throw redirect( throw redirect(
307, 307,
'https://docs.google.com/document/d/1IA9Z5rcIm_KRxvh_L42d2NDdYRHZ72MfszhyJrsmf5A' 'https://docs.google.com/document/d/1IA9Z5rcIm_KRxvh_L42d2NDdYRHZ72MfszhyJrsmf5A'

@ -1,9 +1,9 @@
export async function GET(req) { export async function GET(req) {
const query = req.url.searchParams; const query = req.url.searchParams;
let min = query.get('min') || '0'; const minString = query.get('min') || '0';
let max = query.get('max') || '100'; const maxString = query.get('max') || '100';
min = +min; const min = +minString;
max = +max; const max = +maxString;
// simulate a long delay // simulate a long delay
await new Promise((res) => setTimeout(res, 1000)); await new Promise((res) => setTimeout(res, 1000));

Loading…
Cancel
Save