Skip to content
This repository was archived by the owner on May 15, 2026. It is now read-only.
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
5 changes: 0 additions & 5 deletions browser/components/Status/Status.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { Center, Flex } from "@mantine/core"
import type { ReactNode } from "react"
import { useTranslation } from "react-i18next"
import * as icons from "#icons.ts"
import classes from "./Status.module.css"

Expand All @@ -13,7 +12,6 @@ export interface StatusProps {

export function Status(props: StatusProps) {
const { status } = props
const { t } = useTranslation()

const getIcon = (): ReactNode => {
if (status === "pending")
Expand All @@ -22,16 +20,13 @@ export function Status(props: StatusProps) {
return <icons.Success size={100} className={classes.iconSuccess} />
if (status === "error")
return <icons.Error size={100} className={classes.iconError} />
if (status === "fault")
return <icons.Fault size={100} className={classes.iconFault} />
return null
}

const getTitle = (): string => {
if (status === "pending") return props.pendingTitle
if (status === "success") return props.successTitle
if (status === "error") return props.errorTitle
if (status === "fault") return t("Please try again later")
return ""
}

Expand Down
2 changes: 1 addition & 1 deletion browser/examples/package-invalid-data-external.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"created": "invalid-date-format",
"resources": [
{
"name": "test-data",
"name": "table",
"type": "table",
"path": "table-invalid.csv",
"schema": "schema.json"
Expand Down
2 changes: 1 addition & 1 deletion browser/examples/package-invalid-data-internal.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"created": "invalid-date-format",
"resources": [
{
"name": "test-data",
"name": "table",
"type": "table",
"data": [
["id", "name", "email", "age", "score", "status"],
Expand Down
2 changes: 1 addition & 1 deletion browser/examples/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"created": "invalid-date-format",
"resources": [
{
"name": "test-data",
"name": "table",
"type": "table",
"data": [
["id", "name", "email", "age", "score", "status"],
Expand Down
13 changes: 9 additions & 4 deletions browser/routes/package/validate/Dialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,27 @@ import { store } from "./store.ts"

export function ValidatePackageDialog() {
const { t } = useTranslation()
const error = store.useState(state => state.error)
const report = store.useState(state => state.report)
const isFault = store.useState(state => state.isFault)
const isPending = store.useState(state => state.isPending)
const isDialogOpen = store.useState(state => state.isDialogOpen)

const handleOpenChange = (isDialogOpen: boolean) => {
store.setState({ isDialogOpen, isFault: undefined, report: undefined })
store.setState({ isDialogOpen, error: undefined, report: undefined })
}

const getStatus = () => {
if (report) return report.valid ? "success" : "error"
if (isPending) return "pending"
if (isFault) return "fault"
if (error) return "error"
return undefined
}

const getErrorTitle = () => {
if (error) return t(error.message as any)
return "Invalid data package"
}

return (
<Dialog
open={isDialogOpen}
Expand All @@ -34,7 +39,7 @@ export function ValidatePackageDialog() {
status={getStatus()}
pendingTitle={t("Validating data package...")}
successTitle={t("Valid data package")}
errorTitle={t("Invalid data package")}
errorTitle={getErrorTitle()}
/>

<Report errors={report?.errors as any} />
Expand Down
2 changes: 1 addition & 1 deletion browser/routes/package/validate/queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export function useValidatePackage() {
},
onError: error => {
console.log(error)
store.setState({ isFault: true })
store.setState({ error })
},
})
}
2 changes: 1 addition & 1 deletion browser/routes/package/validate/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import type { api } from "#runtimes/browser/api.ts"
export interface State {
isDialogOpen?: boolean
isPending?: boolean
isFault?: boolean
report?: Awaited<ReturnType<typeof api.package.validate>>
error?: Error
}

export const store = createStore<State>("validatePackage")
6 changes: 3 additions & 3 deletions browser/routes/root.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,12 @@ export function Layout(props: { children: React.ReactNode }) {
<link rel="sitemap" type="text/xml" href="/sitemap.xml" />
<link rel="icon" type="image/png" href="/favicon.png" />

{links.map(link => (
{links.map((link, index) => (
<link
key={index}
rel={link.rel}
hrefLang={link.hreflang}
href={link.href}
key={link.href}
hrefLang={link.hreflang}
/>
))}

Expand Down
16 changes: 16 additions & 0 deletions service/endpoint.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { os } from "@orpc/server"

export const baseEndpoint = os.errors({
ERROR: {},
})

const errorMiddleware = baseEndpoint.middleware(async ({ next, errors }) => {
try {
return await next()
} catch (error) {
const message = error instanceof Error ? error.message : String(error)
throw errors.ERROR({ message })
}
})

export const endpoint = baseEndpoint.use(errorMiddleware)
4 changes: 2 additions & 2 deletions service/endpoints/package/validate.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import * as dpkit from "@dpkit/lib"
import { os } from "@orpc/server"
import * as z from "zod"
import { endpoint } from "../../endpoint.ts"

export const validatePackage = os
export const validatePackage = endpoint
.route({
method: "POST",
path: "/package/validate",
Expand Down