Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion doc/codespaces/welcome.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ $ curl -s localhost:3141/refs/heads/master | jq '.version'
npm run build

# serve assets and expose them externally
npm run start --host
npm run start -- --host
```

## Troubleshooting
Expand Down
9 changes: 1 addition & 8 deletions packages/core/src/Bundle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,7 @@ export async function fetch(
return
}

// TODO: use a schema definition to handle validation failures
// eslint-disable-next-line
const json = await response.json()
const deserialized = deserialize(json)

if (JSON.stringify(serialize(deserialized)) != JSON.stringify(json)) {
throw new Error('Data serialization failure')
}
const deserialized = deserialize(await response.json())

return {
bundle: deserialized,
Expand Down
11 changes: 6 additions & 5 deletions packages/core/src/Ref.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ import { z } from 'zod'

// Ref describes the structure of existing bundled data
export const refSchema = z.intersection(
z.object({ name: z.string() }),
// TODO: name presumably shouldn't be optional, but T000275 needs to be fixed
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@StevenClontz - FWIW, the issue is here, since name is missing. I can file a PR there, but we should also work on making sure that the compiler catches that (if it's something we want to disallow).

Copy link
Member

@StevenClontz StevenClontz Mar 7, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For now, yes, it should be disallowed.

Long-term, reference management is a pain. If we can construct links from IDs (e.g. 1234 to https://site.org/thing/1234) then maybe at some point linking is all we should be doing (and longer-term we can use relevant APIs to complete this information either in the browser or during compilation).

z.object({ name: z.string().optional() }),
z.union([
z.object({ doi: z.string() }),
z.object({ wikipedia: z.string() }),
z.object({ mr: z.string() }),
z.object({ mathse: z.string() }),
z.object({ mo: z.string() }),
z.object({ mathse: z.number() }),
z.object({ mo: z.number() }),
])
)
export type Ref = z.infer<typeof refSchema>
Expand All @@ -31,8 +32,8 @@ export function tag(ref: Ref): TaggedRef {
} else if ('mr' in ref) {
return { kind: 'mr', id: ref.mr, name }
} else if ('mathse' in ref) {
return { kind: 'mathse', id: ref.mathse, name }
return { kind: 'mathse', id: String(ref.mathse), name }
} else {
return { kind: 'mo', id: ref.mo, name }
return { kind: 'mo', id: String(ref.mo), name }
}
}
4 changes: 2 additions & 2 deletions packages/core/test/Bundle.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ describe('Bundle', () => {
{ name: 'doi', doi: 'doi' },
{ name: 'wikipedia', wikipedia: 'wikipedia' },
{ name: 'mr', mr: 'mr' },
{ name: 'mathse', mathse: 'mathse' },
{ name: 'mo', mo: 'mo' },
{ name: 'mathse', mathse: 1 },
{ name: 'mo', mo: 2 },
],
}),
],
Expand Down