|
|
|
@ -1,43 +1,54 @@
|
|
|
|
|
import aloeVera from "$lib/assets/plants/aloe-vera.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 = {
|
|
|
|
|
slug: string;
|
|
|
|
|
name: string;
|
|
|
|
|
bin_name: string;
|
|
|
|
|
const PlantDataTS = t.type({
|
|
|
|
|
slug: t.string,
|
|
|
|
|
name: t.string,
|
|
|
|
|
bin_name: t.string,
|
|
|
|
|
|
|
|
|
|
image: {
|
|
|
|
|
local?: string;
|
|
|
|
|
remote?: string;
|
|
|
|
|
format?: string;
|
|
|
|
|
width?: number;
|
|
|
|
|
source: string;
|
|
|
|
|
alt: string;
|
|
|
|
|
};
|
|
|
|
|
temp: {
|
|
|
|
|
death: number;
|
|
|
|
|
lower: number;
|
|
|
|
|
upper: number;
|
|
|
|
|
};
|
|
|
|
|
care: {
|
|
|
|
|
description: string;
|
|
|
|
|
water_schedule: string;
|
|
|
|
|
mist_schedule?: string;
|
|
|
|
|
fertilize_schedule?: string;
|
|
|
|
|
clean_schedule?: string;
|
|
|
|
|
};
|
|
|
|
|
site: {
|
|
|
|
|
description: string;
|
|
|
|
|
light: string;
|
|
|
|
|
humidity?: string;
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
image: t.type({
|
|
|
|
|
local: t.union([t.string, t.undefined]),
|
|
|
|
|
remote: t.union([t.string, t.undefined]),
|
|
|
|
|
format: t.union([t.string, t.undefined]),
|
|
|
|
|
width: t.union([t.number, t.undefined]),
|
|
|
|
|
source: t.string,
|
|
|
|
|
alt: t.string,
|
|
|
|
|
}),
|
|
|
|
|
temp: t.type({
|
|
|
|
|
death: t.number,
|
|
|
|
|
lower: t.number,
|
|
|
|
|
upper: t.number,
|
|
|
|
|
}),
|
|
|
|
|
care: t.type({
|
|
|
|
|
description: t.string,
|
|
|
|
|
water_schedule: t.string,
|
|
|
|
|
mist_schedule: t.union([t.string, t.undefined]),
|
|
|
|
|
fertilize_schedule: t.union([t.string, t.undefined]),
|
|
|
|
|
clean_schedule: t.union([t.string, t.undefined]),
|
|
|
|
|
}),
|
|
|
|
|
site: t.type({
|
|
|
|
|
description: t.string,
|
|
|
|
|
light: t.string,
|
|
|
|
|
humidity: t.union([t.string, t.undefined]),
|
|
|
|
|
}),
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
export type PlantData = t.TypeOf<typeof PlantDataTS>;
|
|
|
|
|
|
|
|
|
|
type PlantMap = { [key: PlantData["slug"]]: PlantData };
|
|
|
|
|
|
|
|
|
|
export const plants: PlantMap = [aloeVera, monsteraDeliciosa].reduce(
|
|
|
|
|
(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;
|
|
|
|
|
},
|
|
|
|
|
{} as PlantMap,
|
|
|
|
|