diff --git a/src/components/CategoryImplicationItem.svelte b/src/components/CategoryImplicationItem.svelte index b563cb0d7..38b18fc42 100644 --- a/src/components/CategoryImplicationItem.svelte +++ b/src/components/CategoryImplicationItem.svelte @@ -7,9 +7,12 @@ } from '@fortawesome/free-solid-svg-icons' import Fa from 'svelte-fa' import { get_property_url } from '$lib/commons/property.url' - import type { ImplicationDisplay } from '$lib/commons/types' + import type { CategoryImplicationDisplay } from '$lib/commons/types' - type Props = { implication: ImplicationDisplay; highlighted_property?: string } + type Props = { + implication: CategoryImplicationDisplay + highlighted_property?: string + } let { implication, highlighted_property }: Props = $props() diff --git a/src/components/CategoryImplicationList.svelte b/src/components/CategoryImplicationList.svelte index b1151447d..daa90c3ed 100644 --- a/src/components/CategoryImplicationList.svelte +++ b/src/components/CategoryImplicationList.svelte @@ -1,9 +1,9 @@ - -{#if categories.length} - -{:else} -

-{/if} - - diff --git a/src/components/EntityList.svelte b/src/components/EntityList.svelte new file mode 100644 index 000000000..5b3eb8e9d --- /dev/null +++ b/src/components/EntityList.svelte @@ -0,0 +1,37 @@ + + +{#if entities.length} + +{:else} +

+{/if} + + diff --git a/src/components/FunctorList.svelte b/src/components/FunctorList.svelte deleted file mode 100644 index 851e6d0d2..000000000 --- a/src/components/FunctorList.svelte +++ /dev/null @@ -1,38 +0,0 @@ - - -{#if functors.length} - -{:else} -

-{/if} - - diff --git a/src/lib/commons/types.ts b/src/lib/commons/types.ts index bed2e1ef2..a9632a8de 100644 --- a/src/lib/commons/types.ts +++ b/src/lib/commons/types.ts @@ -4,6 +4,11 @@ export type Arrayed = { type Replace>> = Omit & R +export type EntityShort = { + id: string + name: string +} + export type CategoryDisplay = { id: string name: string @@ -17,15 +22,13 @@ export type CategoryDisplay = { dual_category_notation: string | null } -export type CategoryShort = Pick - export type RelatedCategory = Pick export type TagObject = { tag: string } export type CommentObject = { id: number; comment: string } -export type ImplicationDB = { +export type CategoryImplicationDB = { id: string is_equivalence: 0 | 1 reason: string @@ -35,8 +38,8 @@ export type ImplicationDB = { dualized_from?: string | null } -export type ImplicationDisplay = Replace< - ImplicationDB, +export type CategoryImplicationDisplay = Replace< + CategoryImplicationDB, { is_equivalence: boolean is_deduced: boolean @@ -45,6 +48,7 @@ export type ImplicationDisplay = Replace< } > +// used for both categories and functors export type PropertyDB = { id: string relation: string @@ -61,19 +65,26 @@ export type PropertyDisplay = Replace< export type PropertyShort = Pick -export type DescriptionWithReason = { - description: string - reason: string | null -} - -export type CategoryPropertyDB = { +export type PropertyAssignmentDB = { id: string reason: string relation: string is_deduced: 0 | 1 + is_satisfied: 0 | 1 } -export type CategoryProperty = Replace +export type PropertyAssignmentDisplay = Replace< + PropertyAssignmentDB, + { + is_deduced: boolean + is_satisfied: boolean + } +> + +export type DescriptionWithReason = { + description: string + reason: string | null +} export type SpecialObject = { type: string @@ -88,11 +99,6 @@ export type SpecialMorphism = { export type Structure = 'categories' | 'functors' -export type FunctorShort = { - id: string - name: string -} - export type FunctorDB = { id: string name: string @@ -104,24 +110,6 @@ export type FunctorDB = { nlab_link: string | null } -export type FunctorPropertyDB = { - id: string - relation: string - description: string - nlab_link: string | null - invariant_under_equivalences: 0 | 1 - dual_property_id: string | null -} - -export type FunctorPropertyShort = Pick - -export type FunctorProperty = Replace< - FunctorPropertyDB, - { - invariant_under_equivalences: boolean - } -> - export type FunctorImplicationDB = { id: string is_equivalence: 0 | 1 @@ -143,15 +131,3 @@ export type FunctorImplicationDisplay = Replace< target_assumptions: string[] } > - -export type FunctorPropertyAssignmentDB = { - id: string - reason: string - relation: string - is_deduced: 0 | 1 -} - -export type FunctorPropertyAssignment = Replace< - FunctorPropertyAssignmentDB, - { is_deduced: boolean } -> diff --git a/src/lib/server/utils.ts b/src/lib/server/utils.ts index 94318c578..ea47278e8 100644 --- a/src/lib/server/utils.ts +++ b/src/lib/server/utils.ts @@ -1,12 +1,12 @@ import type { FunctorImplicationDB, FunctorImplicationDisplay, - FunctorProperty, - FunctorPropertyDB, - ImplicationDB, - ImplicationDisplay, + CategoryImplicationDB, + CategoryImplicationDisplay, PropertyDB, PropertyDisplay, + PropertyAssignmentDB, + PropertyAssignmentDisplay, } from '$lib/commons/types' export function is_object(obj: unknown): obj is Record { @@ -22,18 +22,7 @@ export function is_subset(a: Set, b: Set) { export const sleep = (delay: number) => new Promise((res) => setTimeout(res, delay)) -export function display_implication(implication: ImplicationDB): ImplicationDisplay { - return { - id: implication.id, - is_equivalence: Boolean(implication.is_equivalence), - reason: implication.reason, - is_deduced: Boolean(implication.is_deduced), - assumptions: JSON.parse(implication.assumptions), - conclusions: JSON.parse(implication.conclusions), - dualized_from: implication.dualized_from, - } -} - +// this function is used for both categories and functors export function display_property(property: PropertyDB): PropertyDisplay { return { id: property.id, @@ -45,14 +34,29 @@ export function display_property(property: PropertyDB): PropertyDisplay { } } -export function display_functor_property(property: FunctorPropertyDB): FunctorProperty { +export function display_property_assignment( + property: PropertyAssignmentDB, +): PropertyAssignmentDisplay { return { id: property.id, + reason: property.reason, + is_deduced: Boolean(property.is_deduced), relation: property.relation, - description: property.description, - dual_property_id: property.dual_property_id, - nlab_link: property.nlab_link, - invariant_under_equivalences: Boolean(property.invariant_under_equivalences), + is_satisfied: Boolean(property.is_satisfied), + } +} + +export function display_implication( + implication: CategoryImplicationDB, +): CategoryImplicationDisplay { + return { + id: implication.id, + is_equivalence: Boolean(implication.is_equivalence), + reason: implication.reason, + is_deduced: Boolean(implication.is_deduced), + assumptions: JSON.parse(implication.assumptions), + conclusions: JSON.parse(implication.conclusions), + dualized_from: implication.dualized_from, } } diff --git a/src/routes/categories/+page.server.ts b/src/routes/categories/+page.server.ts index 597e22e7e..8e827c405 100644 --- a/src/routes/categories/+page.server.ts +++ b/src/routes/categories/+page.server.ts @@ -1,10 +1,10 @@ -import type { CategoryShort, TagObject } from '$lib/commons/types' +import type { EntityShort, TagObject } from '$lib/commons/types' import { batch } from '$lib/server/db.catdat' import { error } from '@sveltejs/kit' import sql from 'sql-template-tag' export const load = async () => { - const { results, err } = batch<[CategoryShort, TagObject]>([ + const { results, err } = batch<[EntityShort, TagObject]>([ sql`SELECT id, name FROM categories ORDER BY lower(name)`, sql`SELECT tag FROM tags ORDER BY id`, ]) diff --git a/src/routes/categories/+page.svelte b/src/routes/categories/+page.svelte index 789df806d..be456e466 100644 --- a/src/routes/categories/+page.svelte +++ b/src/routes/categories/+page.svelte @@ -1,11 +1,11 @@