From 70ae8b17d6ce301cfe4d68a0f429710164dda6aa Mon Sep 17 00:00:00 2001 From: Allan Lasser Date: Tue, 30 Jan 2024 17:08:33 -0500 Subject: [PATCH 01/16] Adds typecheck command and CI step --- .github/workflows/test.yml | 14 ++++++++++++++ package.json | 1 + 2 files changed, 15 insertions(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index ecf7ec911..573c29ae5 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -24,3 +24,17 @@ jobs: env: NODE_ENV: production - run: npm test + typecheck: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + - name: Use Node.js 18.x + uses: actions/setup-node@v3 + with: + node-version: "18.x" + - run: npm ci + - run: npm run build + env: + NODE_ENV: production + - run: npm run typecheck diff --git a/package.json b/package.json index a5765a133..b432a218d 100644 --- a/package.json +++ b/package.json @@ -103,6 +103,7 @@ "test-watch": "NODE_OPTIONS=--experimental-vm-modules jest --watchAll", "test-coverage": "NODE_OPTIONS=--experimental-vm-modules jest --coverage", "test:browser": "playwright test", + "typecheck": "tsc --noEmit", "watch": "concurrently npm:serve npm:dev-embed npm:watch-app", "watch-app": "cross-env NODE_ENV=development webpack watch --config webpack.app.config.js" }, From 551a6dbb8442455579462df94bc145fd857cafca Mon Sep 17 00:00:00 2001 From: Allan Lasser Date: Tue, 30 Jan 2024 17:06:01 -0500 Subject: [PATCH 02/16] Remove `accounts/types` and clean up bad types removes accounts/types reference Updates type of User and Org --- src/addons/dispatch/Premium.svelte | 6 +-- src/api/test/fixtures/empty.ts | 2 +- .../types/{orgAndUser.d.ts => orgAndUser.ts} | 14 ++++--- src/api/types/project.d.ts | 2 + src/common/UploadOptions.svelte | 4 +- src/pages/app/accounts/types.ts | 38 ------------------- src/pages/app/sidebar/DocumentFilters.svelte | 6 +-- 7 files changed, 20 insertions(+), 52 deletions(-) rename src/api/types/{orgAndUser.d.ts => orgAndUser.ts} (74%) delete mode 100644 src/pages/app/accounts/types.ts diff --git a/src/addons/dispatch/Premium.svelte b/src/addons/dispatch/Premium.svelte index c7829b802..71659e996 100644 --- a/src/addons/dispatch/Premium.svelte +++ b/src/addons/dispatch/Premium.svelte @@ -14,7 +14,7 @@ } from "../../manager/orgsAndUsers.js"; import type { AddOnListItem } from "../types"; - import type { User } from "../../pages/app/accounts/types"; + import { type User, isOrg } from "../../api/types/orgAndUser"; export let addon: AddOnListItem; @@ -23,11 +23,11 @@ let spendingLimitEnabled = false; let spendingLimit = 0; - $: creditBalance = user?.organization + $: creditBalance = isOrg(user?.organization) ? getCreditBalance(user.organization) : 0; $: isIndividualOrg = - typeof user?.organization !== "string" && user?.organization?.individual; + isOrg(user?.organization) && user?.organization?.individual; $: isPremium = addon?.parameters?.categories?.includes("premium") ?? false; const { amount, unit, price } = addon?.parameters?.cost ?? {}; diff --git a/src/api/test/fixtures/empty.ts b/src/api/test/fixtures/empty.ts index bae10553d..3842ca970 100644 --- a/src/api/test/fixtures/empty.ts +++ b/src/api/test/fixtures/empty.ts @@ -1,6 +1,6 @@ import type { Page } from "../../types/common"; -export const emptyList: Page = { +export const emptyList: Page = { count: 0, next: null, previous: null, diff --git a/src/api/types/orgAndUser.d.ts b/src/api/types/orgAndUser.ts similarity index 74% rename from src/api/types/orgAndUser.d.ts rename to src/api/types/orgAndUser.ts index 0b293f129..e366fbf59 100644 --- a/src/api/types/orgAndUser.d.ts +++ b/src/api/types/orgAndUser.ts @@ -8,7 +8,7 @@ interface PremiumOrgFields { } export interface Org extends Partial { - id: string; + id: number; name: string; slug: string; avatar_url: string; @@ -27,11 +27,15 @@ export interface IndividualOrg extends Org { } export interface User { - id: string; + id: number; name: Maybe; avatar_url: Maybe; username: string; - organization: string | Org; - organizations: string[]; - admin_organizations: string[]; + organization: number | Org; + organizations: number[]; + admin_organizations: number[]; +} + +export function isOrg(org?: number | Org): org is Org { + return org !== undefined && typeof org !== "number"; } diff --git a/src/api/types/project.d.ts b/src/api/types/project.d.ts index 9ce379603..2c35f0bc4 100644 --- a/src/api/types/project.d.ts +++ b/src/api/types/project.d.ts @@ -9,4 +9,6 @@ export interface Project { private: boolean; updated_at: string; edit_access: boolean; + // TODO: Add 'pinned' field on the server + pinned?: boolean; } diff --git a/src/common/UploadOptions.svelte b/src/common/UploadOptions.svelte index 5f0f06a79..92279727a 100644 --- a/src/common/UploadOptions.svelte +++ b/src/common/UploadOptions.svelte @@ -6,7 +6,7 @@ } from "../api/languages.js"; import { _ } from "svelte-i18n"; import Select from "./Select.svelte"; - import type { Org, User } from "../pages/app/accounts/types.js"; + import { isOrg, type Org, type User } from "../api/types/orgAndUser"; import { getMe, getOrganization } from "../api/orgAndUser.js"; import { onMount } from "svelte"; import { @@ -35,7 +35,7 @@ } try { let activeOrg = user?.organization; - if (typeof activeOrg === "string") { + if (!isOrg(activeOrg)) { org = (await getOrganization(activeOrg)) as Org; } else { org = activeOrg; diff --git a/src/pages/app/accounts/types.ts b/src/pages/app/accounts/types.ts deleted file mode 100644 index 49b32f391..000000000 --- a/src/pages/app/accounts/types.ts +++ /dev/null @@ -1,38 +0,0 @@ -export type Maybe = T | undefined | null; - -interface PremiumOrgFields { - purchased_credits: number; - monthly_credits: number; - monthly_credit_allowance: number; - credit_reset_date: string; -} - -export interface Org extends Partial { - id: string; - name: string; - slug: string; - avatar_url: string; - individual: boolean; - plan: "Free" | "Professional" | "Organization"; -} - -export interface GroupOrg extends Org { - individual: false; - plan: "Free" | "Organization"; -} - -export interface IndividualOrg extends Org { - individual: true; - plan: "Free" | "Professional"; -} - -export interface User { - id: string; - name: Maybe; - avatar_url: Maybe; - username: string; - organization: string | Org; - organizations: string[]; - admin_organizations: string[]; - feature_level: number; -} diff --git a/src/pages/app/sidebar/DocumentFilters.svelte b/src/pages/app/sidebar/DocumentFilters.svelte index 74439936d..090ccbac3 100644 --- a/src/pages/app/sidebar/DocumentFilters.svelte +++ b/src/pages/app/sidebar/DocumentFilters.svelte @@ -1,9 +1,9 @@