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",
"preview": "vite preview",
"start": "node build",
"check": "svelte-kit sync && svelte-check --tsconfig ./jsconfig.json",
"check:watch": "svelte-kit sync && svelte-check --tsconfig ./jsconfig.json --watch",
"check": "node scripts/update.js && svelte-kit sync && svelte-check",
"check:watch": "svelte-kit sync && svelte-check --watch",
"format": "pnpm run check:format -- --write",
"check:format": "prettier --check . --ignore-path .gitignore --plugin-search-dir=."
},

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

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

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

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

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

@ -36,7 +36,7 @@ export async function GET({ 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(
`

@ -1,7 +1,7 @@
import * as cookie from 'cookie';
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') || '');
await session.destroy(cookies.sid);
@ -11,7 +11,7 @@ export async function GET({ request }) {
maxAge: -1,
path: '/',
httpOnly: true,
secure: request.url.protocol === 'https'
secure: url.protocol === 'https'
})
}
});

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

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

Loading…
Cancel
Save