Skip to content

Commit

Permalink
refactor: push SerializedTheorem down to core
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesdabbs committed Jun 15, 2024
1 parent 3e4052c commit 1aa7c49
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 26 deletions.
12 changes: 11 additions & 1 deletion packages/core/src/Theorem.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { z } from 'zod'
import { Ref } from './Ref.js'
import { recordSchema } from './Record.js'
import { formulaSchema } from './Formula.js'
import { Formula, formulaSchema } from './Formula.js'

export const theoremSchema = z.intersection(
z.object({
Expand All @@ -12,3 +13,12 @@ export const theoremSchema = z.intersection(
)

export type Theorem = z.infer<typeof theoremSchema>

// TODO: everything below this line was pushed down and should still be unified
export type SerializedTheorem = {
id: number
when: Formula<number>
then: Formula<number>
description: string
refs: Ref[]
}
2 changes: 1 addition & 1 deletion packages/core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export {
proveTheorem,
} from './Logic/index.js'
export { type Space, SpacePage } from './Space.js'
export { type Theorem } from './Theorem.js'
export { type Theorem, SerializedTheorem } from './Theorem.js'
export { type Trait } from './Trait.js'
export { type Version } from './Bundle.js'

Expand Down
3 changes: 1 addition & 2 deletions packages/viewer/src/__test__/factories.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { TestUtils } from '@pi-base/core'
import { type SerializedTheorem, TestUtils } from '@pi-base/core'

import {
type AssertedTrait,
Collection,
type Property,
type SerializedTheorem,
type Space,
type Trait,
Traits,
Expand Down
12 changes: 3 additions & 9 deletions packages/viewer/src/gateway.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
import * as pb from '@pi-base/core'

import {
Id,
type Property,
type Space,
type SerializedTheorem,
type Trait,
} from './models'
import { Id, type Property, type Space, type Trait } from './models'
import { trace } from './debug'

export type Sync = (
Expand All @@ -18,7 +12,7 @@ export type Sync = (
export type Result = {
spaces: Space[]
properties: Property[]
theorems: SerializedTheorem[]
theorems: pb.SerializedTheorem[]
traits: Trait[]
etag: string
sha: string
Expand Down Expand Up @@ -90,7 +84,7 @@ function theorem({
then,
description,
refs,
}: pb.Theorem): SerializedTheorem {
}: pb.Theorem): pb.SerializedTheorem {
return {
id: Id.toInt(uid),
when: pb.formula.mapProperty(Id.toInt, when),
Expand Down
4 changes: 2 additions & 2 deletions packages/viewer/src/models/Theorem.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { formula as F } from '@pi-base/core'
import { formula as F, type SerializedTheorem } from '@pi-base/core'

import type { Property, Ref, SerializedTheorem } from '@/models'
import type { Property, Ref } from '@/models'

export default class Theorem {
static hydrate(
Expand Down
4 changes: 2 additions & 2 deletions packages/viewer/src/models/Theorems.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { formula as F } from '@pi-base/core'
import { formula as F, type SerializedTheorem } from '@pi-base/core'

import Collection from './Collection'
import { default as Theorem } from './Theorem'
import type { Property, SerializedTheorem } from '@/types'
import type { Property } from '@/types'

export default class Theorems {
static build(
Expand Down
2 changes: 1 addition & 1 deletion packages/viewer/src/stores/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { type SerializedTheorem } from '@pi-base/core'
import type * as Gateway from '@/gateway'
import {
Collection,
Theorems,
Traits,
type Property,
type SerializedTheorem,
type Space,
type Trait,
} from '@/models'
Expand Down
8 changes: 0 additions & 8 deletions packages/viewer/src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,6 @@ export type DeducedTrait = {

export type Trait = AssertedTrait | DeducedTrait

export type SerializedTheorem = {
id: number
when: Formula<number>
then: Formula<number>
description: string
refs: Ref[]
}

export type SerializedProof = {
properties: number[]
theorems: number[]
Expand Down

0 comments on commit 1aa7c49

Please sign in to comment.