UNPKG

@ozmap/ozn-sdk

Version:

OZN SDK is a powerful tool for developers to build their own applications on top of OZN using TMForum pattern.

56 lines (55 loc) 2.37 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.geographicAddressOutputSchema = exports.geographicLocationSchema = exports.geographicAddressInputSchema = void 0; const zod_1 = require("zod"); const shared_1 = require("./shared"); // regex para lat e lng: https://stackoverflow.com/questions/3518504/regular-expression-for-matching-latitude-longitude-coordinates // zod issue https://github.com/colinhacks/zod/issues/2600 exports.geographicAddressInputSchema = zod_1.z .object({ name: zod_1.z.string().min(2).optional(), postcode: zod_1.z.string().min(5).optional(), streetNr: zod_1.z.string().optional(), lat: zod_1.z .string() .regex(/^(\+|-)?(?:90(?:(?:\.0{1,20})?)|(?:[0-9]|[1-8][0-9])(?:(?:\.[0-9]{1,20})?))$/, 'lat must to be between -90 and 90') .optional(), lng: zod_1.z .string() .regex(/^(\+|-)?(?:180(?:(?:\.0{1,20})?)|(?:[0-9]|[1-9][0-9]|1[0-7][0-9])(?:(?:\.[0-9]{1,20})?))$/, 'lng must to be between -180 and 180') .optional(), }) .refine((input) => { const hasCoordinates = input.lat && input.lng; const hasAddress = input.name && input.postcode && input.streetNr; return hasCoordinates || hasAddress; }, 'You must provide at least (lat & lng) or (name, postcode & streetNr).'); exports.geographicLocationSchema = zod_1.z.object({ name: zod_1.z.string(), type: zod_1.z.string(), geometry: zod_1.z.array(zod_1.z.object({ x: zod_1.z.number(), y: zod_1.z.number(), z: zod_1.z.number().nullable(), })), }); exports.geographicAddressOutputSchema = zod_1.z.object({ id: zod_1.z.string().or(zod_1.z.number()), city: zod_1.z.string(), cnl: zod_1.z.string(), country: zod_1.z.string(), locality: zod_1.z.string(), district: zod_1.z.string(), name: zod_1.z.string(), postcode: zod_1.z.string(), stateOrProvince: zod_1.z.string(), streetName: zod_1.z.string(), streetNr: zod_1.z.string().or(zod_1.z.number()), streetType: zod_1.z.string(), streetTitle: zod_1.z.string(), type: zod_1.z.string(), geographicAddressComplement: zod_1.z.string().optional(), geographicLocation: exports.geographicLocationSchema, geographicSubAddress: zod_1.z.string().optional(), externalSystems: zod_1.z.array(shared_1.externalSystemsSchema), });