@tmlmobilidade/types
Version:
This package provides shared Zod validation schemas and their corresponding TypeScript types for use across projects. All types are automatically inferred from the schemas to ensure full type safety and reduce maintenance overhead.
32 lines (31 loc) • 1.76 kB
JavaScript
/*
* Location Types Definition
*
* This file defines two distinct type categories:
*
* 1. DATABASE TYPES: These maintain the complete GeoJSON Feature structure with geometry
* and properties nested within the Feature object. This structure is optimized for
* MongoDB's spatial indexing and querying capabilities, allowing for efficient
* geospatial operations directly on the database.
*
* 2. CODEBASE TYPES: These flatten the GeoJSON structure by extracting properties to the
* top level and moving the complete Feature to a separate 'geojson' field. This makes
* them much easier to work with in application code since you can directly access
* properties like location.name instead of location.properties.name.
*/
import { z } from 'zod';
import { PaginationSchema } from './_common/index.js';
/* * */
export const GetAllDistrictsQuerySchema = z.object({
geojson: z.preprocess((val) => val === 'true' || val === '1', z.boolean()),
});
export const GetAllMunicipalitiesQuerySchema = GetAllDistrictsQuerySchema.extend({
district_ids: z
.preprocess(val => typeof val === 'string' ? val.split(',').map(s => s.trim()).filter(Boolean) : val, z.array(z.string()).nullish()),
});
export const GetAllParishesQuerySchema = GetAllMunicipalitiesQuerySchema.extend({
municipality_ids: z
.preprocess(val => typeof val === 'string' ? val.split(',').map(s => s.trim()).filter(Boolean) : val, z.array(z.string()).nullish()),
}).extend(PaginationSchema.shape);
export const GetAllLocalitiesQuerySchema = GetAllParishesQuerySchema.extend({ parish_ids: z.preprocess(val => typeof val === 'string' ? val.split(',').map(s => s.trim()).filter(Boolean) : val, z.array(z.string()).nullish()),
}).extend(PaginationSchema.shape);