|
|
@ -1,43 +1,54 @@
|
|
|
|
import aloeVera from "$lib/assets/plants/aloe-vera.toml";
|
|
|
|
import aloeVera from "$lib/assets/plants/aloe-vera.toml";
|
|
|
|
import monsteraDeliciosa from "$lib/assets/plants/monstera-deliciosa.toml";
|
|
|
|
import monsteraDeliciosa from "$lib/assets/plants/monstera-deliciosa.toml";
|
|
|
|
|
|
|
|
import { isLeft } from "fp-ts/lib/Either";
|
|
|
|
|
|
|
|
import * as t from "io-ts";
|
|
|
|
|
|
|
|
import { PathReporter } from "io-ts/lib/PathReporter";
|
|
|
|
|
|
|
|
|
|
|
|
export type PlantData = {
|
|
|
|
const PlantDataTS = t.type({
|
|
|
|
slug: string;
|
|
|
|
slug: t.string,
|
|
|
|
name: string;
|
|
|
|
name: t.string,
|
|
|
|
bin_name: string;
|
|
|
|
bin_name: t.string,
|
|
|
|
|
|
|
|
|
|
|
|
image: {
|
|
|
|
image: t.type({
|
|
|
|
local?: string;
|
|
|
|
local: t.union([t.string, t.undefined]),
|
|
|
|
remote?: string;
|
|
|
|
remote: t.union([t.string, t.undefined]),
|
|
|
|
format?: string;
|
|
|
|
format: t.union([t.string, t.undefined]),
|
|
|
|
width?: number;
|
|
|
|
width: t.union([t.number, t.undefined]),
|
|
|
|
source: string;
|
|
|
|
source: t.string,
|
|
|
|
alt: string;
|
|
|
|
alt: t.string,
|
|
|
|
};
|
|
|
|
}),
|
|
|
|
temp: {
|
|
|
|
temp: t.type({
|
|
|
|
death: number;
|
|
|
|
death: t.number,
|
|
|
|
lower: number;
|
|
|
|
lower: t.number,
|
|
|
|
upper: number;
|
|
|
|
upper: t.number,
|
|
|
|
};
|
|
|
|
}),
|
|
|
|
care: {
|
|
|
|
care: t.type({
|
|
|
|
description: string;
|
|
|
|
description: t.string,
|
|
|
|
water_schedule: string;
|
|
|
|
water_schedule: t.string,
|
|
|
|
mist_schedule?: string;
|
|
|
|
mist_schedule: t.union([t.string, t.undefined]),
|
|
|
|
fertilize_schedule?: string;
|
|
|
|
fertilize_schedule: t.union([t.string, t.undefined]),
|
|
|
|
clean_schedule?: string;
|
|
|
|
clean_schedule: t.union([t.string, t.undefined]),
|
|
|
|
};
|
|
|
|
}),
|
|
|
|
site: {
|
|
|
|
site: t.type({
|
|
|
|
description: string;
|
|
|
|
description: t.string,
|
|
|
|
light: string;
|
|
|
|
light: t.string,
|
|
|
|
humidity?: string;
|
|
|
|
humidity: t.union([t.string, t.undefined]),
|
|
|
|
};
|
|
|
|
}),
|
|
|
|
};
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export type PlantData = t.TypeOf<typeof PlantDataTS>;
|
|
|
|
|
|
|
|
|
|
|
|
type PlantMap = { [key: PlantData["slug"]]: PlantData };
|
|
|
|
type PlantMap = { [key: PlantData["slug"]]: PlantData };
|
|
|
|
|
|
|
|
|
|
|
|
export const plants: PlantMap = [aloeVera, monsteraDeliciosa].reduce(
|
|
|
|
export const plants: PlantMap = [aloeVera, monsteraDeliciosa].reduce(
|
|
|
|
(acc, cur) => {
|
|
|
|
(acc, cur) => {
|
|
|
|
acc[cur.slug] = cur;
|
|
|
|
const decoded = PlantDataTS.decode(cur);
|
|
|
|
|
|
|
|
if (isLeft(decoded)) {
|
|
|
|
|
|
|
|
throw Error(
|
|
|
|
|
|
|
|
`Invalid plant data ${PathReporter.report(decoded).join("\n")}`,
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
acc[cur.slug] = decoded.right;
|
|
|
|
return acc;
|
|
|
|
return acc;
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{} as PlantMap,
|
|
|
|
{} as PlantMap,
|
|
|
|