chore: cleanup some code

This commit is contained in:
Torsten Dittmann
2023-08-28 22:55:55 +02:00
parent 1da1041e0d
commit d7cd262362
31 changed files with 109 additions and 90 deletions
+3 -1
View File
@@ -40,7 +40,9 @@ export enum Dependencies {
WEBHOOK = 'dependency:webhook',
WEBHOOKS = 'dependency:webhooks',
MIGRATIONS = 'dependency:migrations',
COLLECTIONS = 'dependency:collections'
COLLECTIONS = 'dependency:collections',
RUNTIMES = 'dependency:runtimes',
CONSOLE_VARIABLES = 'dependency:console_variables'
}
export const scopes: {
+2 -2
View File
@@ -1,6 +1,6 @@
export function debounce<F extends (...params: any[]) => void>(fn: F, delay: number) {
export function debounce<F extends (...params: unknown[]) => void>(fn: F, delay: number) {
let timeoutID: ReturnType<typeof setTimeout> = null;
const debounceFn = function (this: any, ...args: any[]) {
const debounceFn = function (this: unknown, ...args: unknown[]) {
clearTimeout(timeoutID);
timeoutID = window.setTimeout(() => fn.apply(this, args), delay) as unknown as ReturnType<
typeof setTimeout
+1 -1
View File
@@ -45,7 +45,7 @@ export function deepMap<T, U>(
return result;
}
export function parseIfString(value: unknown): any {
export function parseIfString(value: unknown): unknown {
if (typeof value === 'string') {
try {
return JSON.parse(value);
+1 -1
View File
@@ -1,5 +1,5 @@
export function getProjectId() {
const pathname = window.location.pathname;
const pathname = window.location.pathname + '/';
const projectMatch = pathname.match(/\/project-(.*?)\//);
return projectMatch?.[1] || null;
}
+1 -1
View File
@@ -9,7 +9,7 @@ import { deepClone, objectEntries } from './object';
*
* @export
*/
export function createConservative<Obj extends Record<string, any>>(obj: Obj) {
export function createConservative<Obj extends Record<string, unknown>>(obj: Obj) {
const stores = Object.fromEntries(
objectEntries(obj).map(([key, value]) => [key, writable(value)])
) as {
+3 -2
View File
@@ -9,6 +9,7 @@
import { onMount } from 'svelte';
import { ProxyTypes } from '../index.svelte';
import { domain, typeStore } from './store';
import { consoleVariables } from '$routes/console/store';
let error = null;
let isDomainsEnabled = false;
@@ -17,9 +18,9 @@
if (!isSelfHosted) {
return;
}
const vars = await sdk.forConsole.console.variables();
//@ts-expect-error needs an sdk release
isDomainsEnabled = vars?._APP_DOMAIN_ENABLED === true;
isDomainsEnabled = (await $consoleVariables)?._APP_DOMAIN_ENABLED === true;
});
async function createDomain() {
+28 -5
View File
@@ -2,7 +2,7 @@
import CreateTemplate from './createTemplate.svelte';
export function connectTemplate(template: MarketplaceTemplate, runtime: string | null = null) {
const variables: any = {};
const variables: Record<string, string> = {};
template.variables.forEach((variable) => {
variables[variable.name] = variable.value ?? '';
});
@@ -29,17 +29,19 @@
<script lang="ts">
import { base } from '$app/paths';
import { AvatarGroup, Box, Heading } from '$lib/components';
import WizardCover from '$lib/layout/wizardCover.svelte';
import { app } from '$lib/stores/app';
import { wizard } from '$lib/stores/wizard';
import { repository, runtimes, templateConfig, template as templateStore } from './store';
import { repository, templateConfig, template as templateStore } from './store';
import { marketplace, type MarketplaceTemplate } from '$lib/stores/marketplace';
import { Button } from '$lib/elements/forms';
import { page } from '$app/stores';
import { runtimes } from '$routes/console/project-[project]/functions/store';
import { trackEvent } from '$lib/actions/analytics';
import type { Models } from '@appwrite.io/console';
import WizardCover from '$lib/layout/wizardCover.svelte';
import Repositories from './components/repositories.svelte';
import CreateManual from './createManual.svelte';
import CreateGit from './createGit.svelte';
import { Button } from '$lib/elements/forms';
import { page } from '$app/stores';
let hasInstallations: boolean;
let selectedRepository: string;
@@ -48,6 +50,9 @@
const templates = marketplace.filter((template) => template.id !== 'starter').slice(0, 2);
function connect(event: CustomEvent<Models.ProviderRepository>) {
trackEvent('click_connect_repository', {
from: 'cover'
});
repository.set(event.detail);
wizard.start(CreateGit);
}
@@ -109,6 +114,13 @@
)}
<li>
<button
on:click={() => {
trackEvent('click_connect_template', {
from: 'cover',
template: quickStart.id,
runtime: runtime.name
});
}}
on:click={() => connectTemplate(quickStart, runtime.name)}
class="box u-width-full-line u-flex u-cross-center u-gap-8"
style:--box-padding="1rem"
@@ -157,6 +169,12 @@
<li class="clickable-list-item">
<button
type="button"
on:click={() => {
trackEvent('click_connect_template', {
from: 'cover',
template: template.id
});
}}
on:click={() => connectTemplate(template)}
class="clickable-list-button u-width-full-line u-flex u-gap-12">
<div class="avatar is-size-small" style:--p-text-size="1.25rem">
@@ -185,6 +203,11 @@
<p class="u-margin-block-start-16">
You can also create a function <button
class="link"
on:click={() => {
trackEvent('click_create_function_manual', {
from: 'cover'
});
}}
on:click={() => wizard.start(CreateManual)}>manually</button>
or using the CLI.
<a
@@ -4,7 +4,8 @@
import { InputText, InputSelect, FormList } from '$lib/elements/forms';
import { WizardStep } from '$lib/layout';
import { onMount } from 'svelte';
import { createFunction, runtimes } from '../store';
import { createFunction } from '../store';
import { runtimes } from '$routes/console/project-[project]/functions/store';
let showCustomId = false;
@@ -6,7 +6,8 @@
import { WizardStep } from '$lib/layout';
import { onMount } from 'svelte';
import { sdk } from '$lib/stores/sdk';
import { choices, createFunction, installation, repository, runtimes } from '../store';
import { choices, createFunction, installation, repository } from '../store';
import { runtimes } from '$routes/console/project-[project]/functions/store';
let showCustomId = false;
@@ -3,7 +3,8 @@
import { Pill } from '$lib/elements';
import { FormList, InputSelect, InputText } from '$lib/elements/forms';
import { WizardStep } from '$lib/layout';
import { runtimes, template, templateConfig } from '../store';
import { runtimes } from '$routes/console/project-[project]/functions/store';
import { template, templateConfig } from '../store';
let showCustomId = false;
-5
View File
@@ -33,11 +33,6 @@ export const installations = derived(
($page) => $page.data.installations as Models.InstallationList
);
export const runtimes = derived(
page,
($page) => $page.data.runtimes as Promise<Models.RuntimeList>
);
const initialCreateFunction: Partial<Models.Function> = {
$id: null,
name: null,
+1 -1
View File
@@ -25,7 +25,7 @@
onMount(async () => {
if ($page.url.searchParams.has('migrate')) {
const migrateData = $page.url.searchParams.get('migrate');
requestedMigration.set(parseIfString(migrateData));
requestedMigration.set(parseIfString(migrateData) as Record<string, string>);
}
/**
* Reporting Web Vitals.
@@ -15,6 +15,7 @@
resourcesToMigrationForm
} from '$lib/stores/migration';
import { wizard } from '$lib/stores/wizard';
import type { Models } from '@appwrite.io/console';
export let formData: ReturnType<typeof createMigrationFormStore>;
export let provider: ReturnType<typeof createMigrationProviderStore>;
@@ -76,7 +77,7 @@
$formData = resourcesToMigrationForm(resources, version);
}
let report: any;
let report: Models.MigrationReport;
$: version = report?.version || '0.0.0';
let isOpen = false;
@@ -86,18 +87,16 @@
isOpen = true;
try {
switch ($provider.provider) {
case 'appwrite': {
const res = await projectSdk.migrations.getAppwriteReport(
case 'appwrite':
report = await projectSdk.migrations.getAppwriteReport(
providerResources.appwrite,
$provider.endpoint,
$provider.projectID,
$provider.apiKey
);
report = res;
break;
}
case 'supabase': {
const res = await projectSdk.migrations.getSupabaseReport(
case 'supabase':
report = await projectSdk.migrations.getSupabaseReport(
providerResources.supabase,
$provider.endpoint,
$provider.apiKey,
@@ -106,31 +105,25 @@
$provider.password,
$provider.port
);
report = res;
break;
}
case 'firebase': {
case 'firebase':
if ($provider.projectId) {
// OAuth
const res = await sdk.forProject.migrations.getFirebaseReportOAuth(
report = await sdk.forProject.migrations.getFirebaseReportOAuth(
providerResources.firebase,
$provider.projectId
);
report = res;
} else if ($provider.serviceAccount) {
// Manual auth
const res = await projectSdk.migrations.getFirebaseReport(
report = await projectSdk.migrations.getFirebaseReport(
providerResources.firebase,
$provider.serviceAccount
);
report = res;
}
break;
}
case 'nhost': {
const res = await projectSdk.migrations.getNHostReport(
case 'nhost':
report = await projectSdk.migrations.getNHostReport(
providerResources.nhost,
$provider.subdomain,
$provider.region,
@@ -139,8 +132,6 @@
$provider.username,
$provider.password
);
report = res;
}
}
} catch (e) {
if (!isOpen) return;
+2 -3
View File
@@ -23,8 +23,8 @@
import { addNotification } from '$lib/stores/notifications';
import { openMigrationWizard } from './(migration-wizard)';
import { project } from './project-[project]/store';
import { sdk } from '$lib/stores/sdk';
import { feedback } from '$lib/stores/feedback';
import { consoleVariables } from './store';
function kebabToSentenceCase(str: string) {
return str
@@ -35,8 +35,7 @@
let isAssistantEnabled = false;
onMount(async () => {
const vars = await sdk.forConsole.console.variables();
isAssistantEnabled = vars._APP_ASSISTANT_ENABLED === true;
isAssistantEnabled = (await $consoleVariables)?._APP_ASSISTANT_ENABLED === true;
});
$: isOnSettingsLayout = $project?.$id
+6 -1
View File
@@ -1,8 +1,12 @@
import { Dependencies } from '$lib/constants';
import { sdk } from '$lib/stores/sdk';
import type { LayoutLoad } from './$types';
export const load: LayoutLoad = async ({ fetch }) => {
export const load: LayoutLoad = async ({ fetch, depends }) => {
depends(Dependencies.RUNTIMES);
depends(Dependencies.CONSOLE_VARIABLES);
const { endpoint, project } = sdk.forConsole.client.config;
const response = await fetch(`${endpoint}/health/version`, {
headers: {
@@ -12,6 +16,7 @@ export const load: LayoutLoad = async ({ fetch }) => {
const data = await response.json();
return {
consoleVariables: sdk.forConsole.console.variables(),
version: data?.version ?? null
};
};
@@ -73,7 +73,7 @@
};
$: operatorsForColumn = Object.entries(operators)
.filter(([_, v]) => v.types.includes(column?.type))
.filter(([, v]) => v.types.includes(column?.type))
.map(([k]) => ({
label: k,
value: k
@@ -76,7 +76,6 @@ export const queries = initQueries();
export const queriesAreDirty = derived([queries, page], ([$queries, $page]) => {
const paramQueries = $page.url.searchParams.get('query');
const parsedQueries = queryParamToMap(paramQueries || '[]');
console.log({ $queries, parsedQueries, notDirty: deepEqual($queries, parsedQueries) });
return !deepEqual($queries, parsedQueries);
});
@@ -1,9 +1,8 @@
import { Query, type Models } from '@appwrite.io/console';
import { Query } from '@appwrite.io/console';
import { sdk } from '$lib/stores/sdk';
import { getLimit, getPage, pageToOffset } from '$lib/helpers/load';
import { Dependencies, PAGE_LIMIT } from '$lib/constants';
import type { PageLoad } from './$types';
import { isSelfHosted } from '$lib/system';
export const load: PageLoad = async ({ params, depends, url, route, parent }) => {
await parent();
@@ -11,10 +10,6 @@ export const load: PageLoad = async ({ params, depends, url, route, parent }) =>
const page = getPage(url);
const limit = getLimit(url, route, PAGE_LIMIT);
const offset = pageToOffset(page, limit);
let consoleVariables: Models.ConsoleVariables = null;
if (isSelfHosted) {
consoleVariables = await sdk.forConsole.console.variables();
}
return {
offset,
@@ -23,7 +18,6 @@ export const load: PageLoad = async ({ params, depends, url, route, parent }) =>
Query.limit(limit),
Query.offset(offset),
Query.orderDesc('')
]),
consoleVariables
])
};
};
@@ -34,7 +34,7 @@
`functions.${$page.params.function}.deployments.${$page.params.deployment}.update`
)
) {
logs = (message.payload as any).logs as string;
logs = message.payload.buildLogs;
if (message.payload.status === 'ready') {
invalidate(Dependencies.DEPLOYMENT);
}
@@ -49,7 +49,7 @@
import InputSelectSearch from '$lib/elements/forms/inputSelectSearch.svelte';
import { installations } from '$lib/wizards/functions/store';
import { isSelfHosted } from '$lib/system';
import { consoleVariables } from '$lib/stores/consoleVariables';
import { consoleVariables, isVcsEnabled } from '$routes/console/store';
const functionId = $page.params.function;
@@ -172,8 +172,6 @@
selectedBranch !== $func?.providerBranch ||
silentMode !== $func?.providerSilentMode ||
selectedDir !== $func?.providerRootDirectory;
$: isVcsEnabled = $consoleVariables?._APP_VCS_ENABLED === true;
</script>
<Form onSubmit={updateConfiguration}>
@@ -282,7 +280,7 @@
</div>
</Box>
{:else}
{#if isSelfHosted && !isVcsEnabled}
{#if isSelfHosted && !isVcsEnabled($consoleVariables)}
<Alert class="common-section" type="info">
<svelte:fragment slot="title">
Installing Git to a self-hosted instance
@@ -2,7 +2,7 @@ import { page } from '$app/stores';
import { derived } from 'svelte/store';
import type { Models } from '@appwrite.io/console';
export const consoleVariables = derived(
export const runtimes = derived(
page,
($page) => $page.data.consoleVariables as Models.ConsoleVariables
async ($page) => (await $page.data.runtimes) as Models.RuntimeList
);
@@ -4,12 +4,10 @@
import { Pill } from '$lib/elements';
import { Button } from '$lib/elements/forms';
import { Container } from '$lib/layout';
import { consoleVariables } from '$lib/stores/consoleVariables';
import { isSelfHosted } from '$lib/system';
import { connectTemplate } from '$lib/wizards/functions/cover.svelte';
import { consoleVariables, isVcsEnabled } from '$routes/console/store';
import { template } from './store';
$: isVcsEnabled = $consoleVariables?._APP_VCS_ENABLED === true;
</script>
<Container>
@@ -62,7 +60,7 @@
</span>
</Heading>
<p class="u-margin-block-start-24">{$template.tagline}</p>
{#if isSelfHosted && !isVcsEnabled}
{#if isSelfHosted && !isVcsEnabled($consoleVariables)}
<Alert class="u-margin-block-start-24" type="info">
<svelte:fragment slot="title">
Cloning templates to a self-hosted instance
@@ -5,7 +5,7 @@
import { WizardStep } from '$lib/layout';
import { onMount } from 'svelte';
import { createFunction } from './store';
import { runtimes } from '$lib/wizards/functions/store';
import { runtimes } from '../store';
let showCustomId = false;
@@ -12,9 +12,13 @@
export let showEditor = false;
export let variableList: Models.VariableList;
export let sdkCreateVariable: (key: string, value: string) => Promise<any>;
export let sdkUpdateVariable: (variableId: string, key: string, value: string) => Promise<any>;
export let sdkDeleteVariable: (variableId: string) => Promise<any>;
export let sdkCreateVariable: (key: string, value: string) => Promise<unknown>;
export let sdkUpdateVariable: (
variableId: string,
key: string,
value: string
) => Promise<unknown>;
export let sdkDeleteVariable: (variableId: string) => Promise<unknown>;
let error = '';
let envCode = variableList.variables
@@ -1,18 +1,13 @@
import { Dependencies, PAGE_LIMIT } from '$lib/constants';
import { sdk } from '$lib/stores/sdk';
import { Query, type Models } from '@appwrite.io/console';
import { Query } from '@appwrite.io/console';
import type { PageLoad } from './$types';
import { isSelfHosted } from '$lib/system';
export const load: PageLoad = async ({ depends, url }) => {
depends(Dependencies.PROJECT_VARIABLES);
depends(Dependencies.PROJECT_INSTALLATIONS);
const limit = PAGE_LIMIT;
const offset = Number(url.searchParams.get('offset') ?? 0);
let consoleVariables: Models.ConsoleVariables = null;
if (isSelfHosted) {
consoleVariables = await sdk.forConsole.console.variables();
}
return {
limit,
@@ -21,7 +16,6 @@ export const load: PageLoad = async ({ depends, url }) => {
installations: await sdk.forProject.vcs.listInstallations([
Query.limit(limit),
Query.offset(offset)
]),
consoleVariables
])
};
};
@@ -29,7 +29,7 @@
import GitDisconnectModal from './GitDisconnectModal.svelte';
import dayjs from 'dayjs';
import { isSelfHosted } from '$lib/system';
import { consoleVariables } from '$lib/stores/consoleVariables';
import { consoleVariables, isVcsEnabled } from '$routes/console/store';
export let total: number;
export let limit: number;
@@ -76,8 +76,6 @@
noScroll: true
});
}
$: isVcsEnabled = $consoleVariables?._APP_VCS_ENABLED === true;
</script>
<CardGrid>
@@ -181,7 +179,7 @@
bind:offset />
</div>
{:else}
{#if isSelfHosted && !isVcsEnabled}
{#if isSelfHosted && !isVcsEnabled($consoleVariables)}
<Alert type="info">
<svelte:fragment slot="title">
Installing Git to a self-hosted instance
@@ -4,7 +4,6 @@ import type { BarSeriesOption } from 'echarts/charts';
import { derived, writable } from 'svelte/store';
export const project = derived(page, ($page) => $page.data.project as Models.Project);
export const onboarding = derived(
project,
($project) => $project?.platforms?.length === 0 && $project?.keys?.length === 0
@@ -37,9 +37,13 @@
export let globalVariableList: Models.VariableList | undefined = undefined;
export let isGlobal: boolean;
export let sdkCreateVariable: (key: string, value: string) => Promise<any>;
export let sdkUpdateVariable: (variableId: string, key: string, value: string) => Promise<any>;
export let sdkDeleteVariable: (variableId: string) => Promise<any>;
export let sdkCreateVariable: (key: string, value: string) => Promise<unknown>;
export let sdkUpdateVariable: (
variableId: string,
key: string,
value: string
) => Promise<unknown>;
export let sdkDeleteVariable: (variableId: string) => Promise<unknown>;
let showVariablesDropdown = [];
let selectedVar: Models.Variable = null;
@@ -9,8 +9,12 @@
export let isGlobal: boolean;
export let show = false;
export let variableList: Models.VariableList;
export let sdkCreateVariable: (key: string, value: string) => Promise<any>;
export let sdkUpdateVariable: (variableId: string, key: string, value: string) => Promise<any>;
export let sdkCreateVariable: (key: string, value: string) => Promise<unknown>;
export let sdkUpdateVariable: (
variableId: string,
key: string,
value: string
) => Promise<unknown>;
let files: FileList;
let error: string;
+8
View File
@@ -1,4 +1,12 @@
import { page } from '$app/stores';
import type { Models } from '@appwrite.io/console';
import { derived } from 'svelte/store';
export const version = derived(page, ($page) => $page.data.version as string | null);
export const consoleVariables = derived(
page,
async ($page) => (await $page.data.consoleVariables) as Models.ConsoleVariables
);
export async function isVcsEnabled(store: Promise<Models.ConsoleVariables>) {
return (await store)?._APP_VCS_ENABLED === true;
}
+1 -1
View File
@@ -7,4 +7,4 @@ export const loading = writable(true);
export const organizations = derived(page, ($page) => {
return $page.data.organizations as Models.TeamList<Models.Preferences>;
});
export const requestedMigration = writable<Record<string, any> | null>(null);
export const requestedMigration = writable<Record<string, string> | null>(null);