Skip to content

Commit

Permalink
fix: geojson schemas in declaration file
Browse files Browse the repository at this point in the history
  • Loading branch information
ctot-nondef committed Oct 18, 2024
1 parent 8d8564d commit 6bfc6e9
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 19 deletions.
3 changes: 2 additions & 1 deletion composables/use-geojson.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { useQuery } from "@tanstack/vue-query";

import { type FeatureCollectionType, GeoFeatureSchema } from "@/types/global.d.ts";
import { GeoFeatureSchema } from "@/types/geojson";
import type { FeatureCollectionType } from "@/types/global.d.ts";

export function useGeojson(options?: { enabled?: boolean }) {
const api = useApiClient();
Expand Down
20 changes: 20 additions & 0 deletions types/geojson.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { z } from "zod";

export const GeoFeatureSchema = z.object({
type: z.literal("Feature"),
id: z.string(),
geometry: z.object({
type: z.literal("Point"),
coordinates: z.array(z.number()),
}),
properties: z.any(),
});

export const FeatureCollectionSchema = z.object({
type: z.literal("FeatureCollection"),
properties: z.object({
name: z.string(),
column_headings: z.array(z.any()),
}),
features: z.array(GeoFeatureSchema),
});
20 changes: 2 additions & 18 deletions types/global.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import type { Ref } from "vue";
import { z } from "zod";

import type { FeatureCollectionSchema, GeoFeatureSchema } from "@/types/geojson";

type MaybeRef<T> = Ref<T> | T;

export const DataTypesEnum = z.enum(["Profile", "Text", "SampleText", "Feature", "CorpusText"]);
Expand Down Expand Up @@ -246,25 +248,7 @@ export type WindowItemMap = {
[TargetType in WindowItemTargetType]: Extract<WindowItem, { targetType: TargetType }>;
};

export const GeoFeatureSchema = z.object({
type: z.literal("Feature"),
id: z.string(),
geometry: z.object({
type: z.literal("Point"),
coordinates: z.array(z.number()),
}),
properties: z.any(),
});
export type FeatureType = z.infer<typeof GeoFeatureSchema>;

export const FeatureCollectionSchema = z.object({
type: z.literal("FeatureCollection"),
properties: z.object({
name: z.string(),
column_headings: z.array(z.any()),
}),
features: z.array(GeoFeatureSchema),
});
export type FeatureCollectionType = z.infer<typeof FeatureCollectionSchema>;

export interface VicavHTTPError extends Error {
Expand Down

0 comments on commit 6bfc6e9

Please sign in to comment.