diff --git a/src/tools/gpfWfsGetFeatures/compile.ts b/src/helpers/wfs_internal/compile.ts similarity index 96% rename from src/tools/gpfWfsGetFeatures/compile.ts rename to src/helpers/wfs_internal/compile.ts index 50b26d0..d4440f3 100644 --- a/src/tools/gpfWfsGetFeatures/compile.ts +++ b/src/helpers/wfs_internal/compile.ts @@ -602,19 +602,35 @@ export function getSpatialFilter(input: GpfWfsGetFeaturesInput): SpatialFilter | } /** - * Builds the list of non-geometric properties to request from the WFS layer. + * Build the list of property names to return in the WFS response according to the `select` and `result_type` input parameters. * + * Note that : + * - When `select` is omitted and `result_type` is `results`, all non-geometric properties are returned. + * - When `select` is provided, the specified properties are validated according to the featureType from the Catalog. + * * @param featureType Feature type definition loaded from the embedded catalog. * @param geometryProperty Geometry property already resolved for the feature type. * @param input Normalized tool input. - * @returns The list of selected property names, or every non-geometric property when `select` is omitted. + * @returns The list of non-geometric property names to include in the WFS `propertyName` parameter, or an empty list to include all properties. +* */ function buildSelectList(featureType: Collection, geometryProperty: CollectionProperty, input: GpfWfsGetFeaturesInput) { - return input.select && input.select.length > 0 - ? input.select.map((propertyName) => compileSelectProperty(featureType, geometryProperty, propertyName)) - : featureType.properties + // if `select` is specified, we only return the requested properties (after validation) + if (input.select && input.select.length > 0) { + return input.select.map((propertyName) => compileSelectProperty(featureType, geometryProperty, propertyName)); + } + + // if `select` is omitted and result_type is `results`, + // we return every non-geometric property + if (input.result_type === "results") { + return featureType.properties .filter((property) => !property.defaultCrs) .map((property) => property.name); + } + + // if `select` is omitted and result_type is `hits` or `request` + // we don't specify any propertyName + return []; } // --- Query Compilation --- diff --git a/src/tools/gpfWfsGetFeatures/request.ts b/src/helpers/wfs_internal/request.ts similarity index 100% rename from src/tools/gpfWfsGetFeatures/request.ts rename to src/helpers/wfs_internal/request.ts diff --git a/src/tools/gpfWfsGetFeatures/response.ts b/src/helpers/wfs_internal/response.ts similarity index 100% rename from src/tools/gpfWfsGetFeatures/response.ts rename to src/helpers/wfs_internal/response.ts diff --git a/src/tools/gpfWfsGetFeatures/schema.ts b/src/helpers/wfs_internal/schema.ts similarity index 100% rename from src/tools/gpfWfsGetFeatures/schema.ts rename to src/helpers/wfs_internal/schema.ts diff --git a/src/tools/GpfWfsGetFeaturesTool.ts b/src/tools/GpfWfsGetFeaturesTool.ts index fbbd269..284cbe3 100644 --- a/src/tools/GpfWfsGetFeaturesTool.ts +++ b/src/tools/GpfWfsGetFeaturesTool.ts @@ -5,16 +5,16 @@ import { wfsClient } from "../gpf/wfs.js"; import { fetchJSONPost } from "../helpers/http.js"; import logger from "../logger.js"; import { READ_ONLY_OPEN_WORLD_TOOL_ANNOTATIONS } from "../helpers/toolAnnotations.js"; -import { compileQueryParts, geometryToEwkt, getGeometryProperty, getSpatialFilter } from "./gpfWfsGetFeatures/compile.js"; -import { buildMainRequest, buildReferenceGeometryRequest, type CompiledRequest } from "./gpfWfsGetFeatures/request.js"; -import { transformFeatureCollectionResponse } from "./gpfWfsGetFeatures/response.js"; +import { compileQueryParts, geometryToEwkt, getGeometryProperty, getSpatialFilter } from "../helpers/wfs_internal/compile.js"; +import { buildMainRequest, buildReferenceGeometryRequest, type CompiledRequest } from "../helpers/wfs_internal/request.js"; +import { transformFeatureCollectionResponse } from "../helpers/wfs_internal/response.js"; import { gpfWfsGetFeaturesHitsOutputSchema, gpfWfsGetFeaturesInputSchema, type GpfWfsGetFeaturesInput, gpfWfsGetFeaturesPublishedInputSchema, gpfWfsGetFeaturesRequestOutputSchema, -} from "./gpfWfsGetFeatures/schema.js"; +} from "../helpers/wfs_internal/schema.js"; class GpfWfsGetFeaturesTool extends MCPTool { name = "gpf_wfs_get_features"; diff --git a/test/gpfWfsGetFeatures/compile.test.ts b/test/helpers/wfs_internal/compile.test.ts similarity index 95% rename from test/gpfWfsGetFeatures/compile.test.ts rename to test/helpers/wfs_internal/compile.test.ts index c1f85e8..2ed7735 100644 --- a/test/gpfWfsGetFeatures/compile.test.ts +++ b/test/helpers/wfs_internal/compile.test.ts @@ -1,7 +1,7 @@ import type { Collection } from "@ignfab/gpf-schema-store"; -import { compileQueryParts, geometryToEwkt } from "../../src/tools/gpfWfsGetFeatures/compile"; -import type { GpfWfsGetFeaturesInput } from "../../src/tools/gpfWfsGetFeatures/schema"; +import { compileQueryParts, geometryToEwkt } from "../../../src/helpers/wfs_internal/compile"; +import type { GpfWfsGetFeaturesInput } from "../../../src/helpers/wfs_internal/schema"; describe("gpfWfsGetFeatures/compile", () => { const featureType: Collection = { @@ -119,4 +119,5 @@ describe("gpfWfsGetFeatures/compile", () => { expect(geometryToEwkt({ type: "MultiPoint", coordinates: [[2.3, 48.8], [2.4, 48.9]] })).toEqual("SRID=4326;MULTIPOINT((2.3 48.8),(2.4 48.9))"); expect(geometryToEwkt({ type: "LineString", coordinates: [[2.3, 48.8], [2.4, 48.9]] })).toEqual("SRID=4326;LINESTRING(2.3 48.8,2.4 48.9)"); }); + });