{"version":3,"file":"geojson.mjs","names":[],"sources":["../../../../3-extensions/postgis/dist/geojson.mjs"],"sourcesContent":["import { t as postgisError } from \"./errors-Bg6kDFR-.mjs\";\n//#region src/core/geojson.ts\n/**\n* GeoJSON-shaped value types used by the PostGIS codec.\n*\n* The codec speaks GeoJSON-style objects to JavaScript callers and\n* EWKT/EWKB on the wire. This file is the single source of truth for the\n* value shapes; the public type re-export lives in `exports/geojson.ts`.\n*/\n/**\n* Construct a Point. Convenience for the common \"lng/lat\" case.\n*\n* @example\n*   point(-122.4194, 37.7749, 4326)\n*/\nfunction point(longitude, latitude, srid) {\n\tif (!Number.isFinite(longitude) || !Number.isFinite(latitude)) throw postgisError(\"POSTGIS.GEOMETRY_INVALID\", \"point: coordinates must be finite numbers\", { meta: {\n\t\thelper: \"point\",\n\t\treason: \"non-finite coordinates\"\n\t} });\n\treturn srid !== void 0 ? {\n\t\ttype: \"Point\",\n\t\tcoordinates: [longitude, latitude],\n\t\tsrid\n\t} : {\n\t\ttype: \"Point\",\n\t\tcoordinates: [longitude, latitude]\n\t};\n}\n/**\n* Construct a Polygon from a single outer ring of `[lng, lat]` pairs.\n* If the first and last positions differ, the ring is closed automatically.\n*/\nfunction polygon(ring, srid) {\n\tif (ring.length < 3) throw postgisError(\"POSTGIS.GEOMETRY_INVALID\", \"polygon: ring must contain at least 3 positions\", { meta: {\n\t\thelper: \"polygon\",\n\t\treason: \"ring under 3 positions\"\n\t} });\n\tconst first = ring[0];\n\tconst last = ring[ring.length - 1];\n\tif (!first || !last) throw postgisError(\"POSTGIS.GEOMETRY_INVALID\", \"polygon: ring positions cannot be undefined\", { meta: {\n\t\thelper: \"polygon\",\n\t\treason: \"undefined ring position\"\n\t} });\n\tfor (const position of ring) if (!Number.isFinite(position[0]) || !Number.isFinite(position[1])) throw postgisError(\"POSTGIS.GEOMETRY_INVALID\", \"polygon: coordinates must be finite numbers\", { meta: {\n\t\thelper: \"polygon\",\n\t\treason: \"non-finite coordinates\"\n\t} });\n\tconst closed = first[0] === last[0] && first[1] === last[1] ? ring : [...ring, first];\n\tif (new Set(closed.slice(0, -1).map(([x, y]) => `${x},${y}`)).size < 3) throw postgisError(\"POSTGIS.GEOMETRY_INVALID\", \"polygon: ring must contain at least 3 distinct positions\", { meta: {\n\t\thelper: \"polygon\",\n\t\treason: \"ring under 3 distinct positions\"\n\t} });\n\treturn srid !== void 0 ? {\n\t\ttype: \"Polygon\",\n\t\tcoordinates: [closed],\n\t\tsrid\n\t} : {\n\t\ttype: \"Polygon\",\n\t\tcoordinates: [closed]\n\t};\n}\n/**\n* Construct a rectangular Polygon from a bounding box.\n*\n* @param bbox - `[minLng, minLat, maxLng, maxLat]`\n*/\nfunction bboxPolygon(bbox, srid) {\n\tconst [minX, minY, maxX, maxY] = bbox;\n\tif (!Number.isFinite(minX) || !Number.isFinite(minY) || !Number.isFinite(maxX) || !Number.isFinite(maxY)) throw postgisError(\"POSTGIS.GEOMETRY_INVALID\", \"bboxPolygon: coordinates must be finite numbers\", { meta: {\n\t\thelper: \"bboxPolygon\",\n\t\treason: \"non-finite coordinates\"\n\t} });\n\tif (minX > maxX || minY > maxY) throw postgisError(\"POSTGIS.GEOMETRY_INVALID\", `bboxPolygon: inverted bbox [${minX}, ${minY}, ${maxX}, ${maxY}] (expected minX <= maxX and minY <= maxY)`, { meta: {\n\t\thelper: \"bboxPolygon\",\n\t\treason: \"inverted bbox\"\n\t} });\n\treturn polygon([\n\t\t[minX, minY],\n\t\t[maxX, minY],\n\t\t[maxX, maxY],\n\t\t[minX, maxY],\n\t\t[minX, minY]\n\t], srid);\n}\n//#endregion\nexport { bboxPolygon, point, polygon };\n\n//# sourceMappingURL=geojson.mjs.map"],"mappings":";;;;;;;;;;;;;;;AAeA,SAAS,MAAM,WAAW,UAAU,MAAM;CACzC,IAAI,CAAC,OAAO,SAAS,SAAS,KAAK,CAAC,OAAO,SAAS,QAAQ,GAAG,MAAM,aAAa,4BAA4B,6CAA6C,EAAE,MAAM;EAClK,QAAQ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