@ignfab/geocontext 0.9.6 → 0.9.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (126) hide show
  1. package/README.md +334 -257
  2. package/dist/gpf/adminexpress.d.ts +17 -8
  3. package/dist/gpf/adminexpress.js +40 -17
  4. package/dist/gpf/adminexpress.js.map +1 -1
  5. package/dist/gpf/altitude.d.ts +21 -9
  6. package/dist/gpf/altitude.js +5 -5
  7. package/dist/gpf/altitude.js.map +1 -1
  8. package/dist/gpf/geocode.d.ts +25 -4
  9. package/dist/gpf/geocode.js +5 -5
  10. package/dist/gpf/geocode.js.map +1 -1
  11. package/dist/gpf/parcellaire-express.d.ts +19 -9
  12. package/dist/gpf/parcellaire-express.js +59 -26
  13. package/dist/gpf/parcellaire-express.js.map +1 -1
  14. package/dist/gpf/urbanisme.d.ts +24 -16
  15. package/dist/gpf/urbanisme.js +81 -33
  16. package/dist/gpf/urbanisme.js.map +1 -1
  17. package/dist/gpf/{wfs.js → wfs-schema-catalog.js} +1 -1
  18. package/dist/gpf/wfs-schema-catalog.js.map +1 -0
  19. package/dist/helpers/RateLimiter.d.ts +44 -0
  20. package/dist/helpers/RateLimiter.js +52 -0
  21. package/dist/helpers/RateLimiter.js.map +1 -0
  22. package/dist/helpers/distance.d.ts +2 -1
  23. package/dist/helpers/distance.js +2 -1
  24. package/dist/helpers/distance.js.map +1 -1
  25. package/dist/helpers/errors/toolError.d.ts +30 -0
  26. package/dist/helpers/errors/toolError.js +193 -0
  27. package/dist/helpers/errors/toolError.js.map +1 -0
  28. package/dist/helpers/errors/zodErrorMapFr.d.ts +20 -0
  29. package/dist/helpers/errors/zodErrorMapFr.js +191 -0
  30. package/dist/helpers/errors/zodErrorMapFr.js.map +1 -0
  31. package/dist/helpers/http.d.ts +67 -7
  32. package/dist/helpers/http.js +458 -84
  33. package/dist/helpers/http.js.map +1 -1
  34. package/dist/helpers/jsonSchema.d.ts +16 -4
  35. package/dist/helpers/jsonSchema.js +7 -1
  36. package/dist/helpers/jsonSchema.js.map +1 -1
  37. package/dist/helpers/schemas.d.ts +4 -4
  38. package/dist/helpers/wfs_engine/attributeFilter.d.ts +51 -0
  39. package/dist/helpers/wfs_engine/attributeFilter.js +258 -0
  40. package/dist/helpers/wfs_engine/attributeFilter.js.map +1 -0
  41. package/dist/helpers/wfs_engine/byId.d.ts +76 -0
  42. package/dist/helpers/wfs_engine/byId.js +106 -0
  43. package/dist/helpers/wfs_engine/byId.js.map +1 -0
  44. package/dist/helpers/wfs_engine/execution.d.ts +72 -0
  45. package/dist/helpers/wfs_engine/execution.js +95 -0
  46. package/dist/helpers/wfs_engine/execution.js.map +1 -0
  47. package/dist/helpers/wfs_engine/features.d.ts +64 -0
  48. package/dist/helpers/wfs_engine/features.js +138 -0
  49. package/dist/helpers/wfs_engine/features.js.map +1 -0
  50. package/dist/helpers/wfs_engine/geometry.d.ts +16 -0
  51. package/dist/helpers/wfs_engine/geometry.js +44 -0
  52. package/dist/helpers/wfs_engine/geometry.js.map +1 -0
  53. package/dist/helpers/wfs_engine/properties.d.ts +51 -0
  54. package/dist/helpers/wfs_engine/properties.js +128 -0
  55. package/dist/helpers/wfs_engine/properties.js.map +1 -0
  56. package/dist/helpers/wfs_engine/queryPreparation.d.ts +32 -0
  57. package/dist/helpers/wfs_engine/queryPreparation.js +149 -0
  58. package/dist/helpers/wfs_engine/queryPreparation.js.map +1 -0
  59. package/dist/helpers/{wfs_internal → wfs_engine}/request.d.ts +49 -2
  60. package/dist/helpers/{wfs_internal → wfs_engine}/request.js +77 -1
  61. package/dist/helpers/wfs_engine/request.js.map +1 -0
  62. package/dist/helpers/wfs_engine/response.d.ts +80 -0
  63. package/dist/helpers/wfs_engine/response.js +135 -0
  64. package/dist/helpers/wfs_engine/response.js.map +1 -0
  65. package/dist/helpers/wfs_engine/schema.d.ts +209 -0
  66. package/dist/helpers/{wfs_internal → wfs_engine}/schema.js +50 -10
  67. package/dist/helpers/wfs_engine/schema.js.map +1 -0
  68. package/dist/helpers/wfs_engine/spatialCql.d.ts +46 -0
  69. package/dist/helpers/wfs_engine/spatialCql.js +54 -0
  70. package/dist/helpers/wfs_engine/spatialCql.js.map +1 -0
  71. package/dist/helpers/wfs_engine/spatialFilter.d.ts +14 -0
  72. package/dist/helpers/wfs_engine/spatialFilter.js +131 -0
  73. package/dist/helpers/wfs_engine/spatialFilter.js.map +1 -0
  74. package/dist/index.js +65 -23
  75. package/dist/index.js.map +1 -1
  76. package/dist/logger.d.ts +1 -1
  77. package/dist/logger.js +4 -1
  78. package/dist/logger.js.map +1 -1
  79. package/dist/tools/AdminexpressTool.d.ts +42 -33
  80. package/dist/tools/AdminexpressTool.js +17 -2
  81. package/dist/tools/AdminexpressTool.js.map +1 -1
  82. package/dist/tools/AltitudeTool.d.ts +35 -44
  83. package/dist/tools/AltitudeTool.js +19 -8
  84. package/dist/tools/AltitudeTool.js.map +1 -1
  85. package/dist/tools/AssietteSupTool.d.ts +51 -34
  86. package/dist/tools/AssietteSupTool.js +17 -2
  87. package/dist/tools/AssietteSupTool.js.map +1 -1
  88. package/dist/tools/BaseTool.d.ts +17 -0
  89. package/dist/tools/BaseTool.js +41 -0
  90. package/dist/tools/BaseTool.js.map +1 -0
  91. package/dist/tools/CadastreTool.d.ts +53 -33
  92. package/dist/tools/CadastreTool.js +17 -2
  93. package/dist/tools/CadastreTool.js.map +1 -1
  94. package/dist/tools/GeocodeTool.d.ts +53 -37
  95. package/dist/tools/GeocodeTool.js +17 -2
  96. package/dist/tools/GeocodeTool.js.map +1 -1
  97. package/dist/tools/GpfWfsDescribeTypeTool.d.ts +66 -94
  98. package/dist/tools/GpfWfsDescribeTypeTool.js +25 -14
  99. package/dist/tools/GpfWfsDescribeTypeTool.js.map +1 -1
  100. package/dist/tools/GpfWfsGetFeatureByIdTool.d.ts +52 -73
  101. package/dist/tools/GpfWfsGetFeatureByIdTool.js +50 -107
  102. package/dist/tools/GpfWfsGetFeatureByIdTool.js.map +1 -1
  103. package/dist/tools/GpfWfsGetFeaturesTool.d.ts +89 -114
  104. package/dist/tools/GpfWfsGetFeaturesTool.js +29 -120
  105. package/dist/tools/GpfWfsGetFeaturesTool.js.map +1 -1
  106. package/dist/tools/GpfWfsSearchTypesTool.d.ts +41 -32
  107. package/dist/tools/GpfWfsSearchTypesTool.js +18 -3
  108. package/dist/tools/GpfWfsSearchTypesTool.js.map +1 -1
  109. package/dist/tools/UrbanismeTool.d.ts +42 -33
  110. package/dist/tools/UrbanismeTool.js +17 -2
  111. package/dist/tools/UrbanismeTool.js.map +1 -1
  112. package/package.json +51 -24
  113. package/dist/gpf/wfs.js.map +0 -1
  114. package/dist/helpers/wfs.d.ts +0 -27
  115. package/dist/helpers/wfs.js +0 -55
  116. package/dist/helpers/wfs.js.map +0 -1
  117. package/dist/helpers/wfs_internal/compile.d.ts +0 -55
  118. package/dist/helpers/wfs_internal/compile.js +0 -596
  119. package/dist/helpers/wfs_internal/compile.js.map +0 -1
  120. package/dist/helpers/wfs_internal/request.js.map +0 -1
  121. package/dist/helpers/wfs_internal/response.d.ts +0 -29
  122. package/dist/helpers/wfs_internal/response.js +0 -59
  123. package/dist/helpers/wfs_internal/response.js.map +0 -1
  124. package/dist/helpers/wfs_internal/schema.d.ts +0 -167
  125. package/dist/helpers/wfs_internal/schema.js.map +0 -1
  126. /package/dist/gpf/{wfs.d.ts → wfs-schema-catalog.d.ts} +0 -0
@@ -0,0 +1,32 @@
1
+ /**
2
+ * Query preparation helpers for the structured WFS engine.
3
+ *
4
+ * This module centralizes:
5
+ * - compilation of attribute clauses into CQL fragments
6
+ * - compilation of spatial filters into CQL fragments
7
+ * - assembly of query parts used by WFS request builders
8
+ * - a small façade over lower-level helpers reused elsewhere in the engine
9
+ */
10
+ import type { Collection, CollectionProperty } from "@ignfab/gpf-schema-store";
11
+ import type { GpfWfsGetFeaturesInput } from "./schema.js";
12
+ export { geometryToEwkt } from "./geometry.js";
13
+ export { validateSelectProperty, getGeometryProperty } from "./properties.js";
14
+ export { getSpatialFilter } from "./spatialFilter.js";
15
+ export type ResolvedFeatureGeometryRef = {
16
+ geometry_ewkt: string;
17
+ };
18
+ export type CompiledQuery = {
19
+ geometryProperty: CollectionProperty;
20
+ cqlFilter?: string;
21
+ propertyName?: string;
22
+ sortBy?: string;
23
+ };
24
+ /**
25
+ * Compiles normalized tool input into query fragments ready to be turned into a WFS request.
26
+ *
27
+ * @param input Normalized tool input.
28
+ * @param featureType Feature type definition loaded from the embedded catalog.
29
+ * @param resolvedGeometryRef Optional resolved reference geometry for `intersects_feature`.
30
+ * @returns Compiled query parts used by request builders.
31
+ */
32
+ export declare function compileQueryParts(input: GpfWfsGetFeaturesInput, featureType: Collection, resolvedGeometryRef?: ResolvedFeatureGeometryRef): CompiledQuery;
@@ -0,0 +1,149 @@
1
+ /**
2
+ * Query preparation helpers for the structured WFS engine.
3
+ *
4
+ * This module centralizes:
5
+ * - compilation of attribute clauses into CQL fragments
6
+ * - compilation of spatial filters into CQL fragments
7
+ * - assembly of query parts used by WFS request builders
8
+ * - a small façade over lower-level helpers reused elsewhere in the engine
9
+ */
10
+ import { buildSelectList, resolveNonGeometryProperty, getGeometryProperty, } from "./properties.js";
11
+ import { getSpatialFilter } from "./spatialFilter.js";
12
+ import { formatScalarValue, normalizeWhereClause, SCALAR_COMPARISON_OPERATORS, NUMERIC_COMPARISON_OPERATORS, } from "./attributeFilter.js";
13
+ import { compileBboxSpatialFilter, compileDwithinSpatialFilter, compileIntersectsFeatureSpatialFilter, compileIntersectsPointSpatialFilter, } from "./spatialCql.js";
14
+ // --- Re-exports ---
15
+ export { geometryToEwkt } from "./geometry.js";
16
+ export { validateSelectProperty, getGeometryProperty } from "./properties.js";
17
+ export { getSpatialFilter } from "./spatialFilter.js";
18
+ // --- Internal Constants ---
19
+ const ORDER_DIRECTION_TO_WFS = {
20
+ asc: "A",
21
+ desc: "D",
22
+ };
23
+ // --- Attribute Compilation ---
24
+ /**
25
+ * Compiles a normalized scalar comparison (`eq` / `ne`) into a CQL fragment.
26
+ *
27
+ * @param property Non-geometric property targeted by the clause.
28
+ * @param clause Normalized scalar comparison clause.
29
+ * @returns A CQL predicate fragment.
30
+ */
31
+ function compileScalarComparisonClause(property, clause) {
32
+ return `${property.name} ${SCALAR_COMPARISON_OPERATORS[clause.operator]} ${formatScalarValue(clause.value)}`;
33
+ }
34
+ /**
35
+ * Compiles a normalized ordered comparison (`lt` / `lte` / `gt` / `gte`) into a CQL fragment.
36
+ *
37
+ * @param property Non-geometric property targeted by the clause.
38
+ * @param clause Normalized ordered comparison clause.
39
+ * @returns A CQL predicate fragment.
40
+ */
41
+ function compileOrderedComparisonClause(property, clause) {
42
+ return `${property.name} ${NUMERIC_COMPARISON_OPERATORS[clause.operator]} ${formatScalarValue(clause.value)}`;
43
+ }
44
+ /**
45
+ * Compiles a normalized `in` clause into a CQL fragment.
46
+ *
47
+ * @param property Non-geometric property targeted by the clause.
48
+ * @param clause Normalized `in` clause.
49
+ * @returns A CQL predicate fragment.
50
+ */
51
+ function compileInClause(property, clause) {
52
+ return `${property.name} IN (${clause.values.map(formatScalarValue).join(", ")})`;
53
+ }
54
+ /**
55
+ * Compiles a normalized `is_null` clause into a CQL fragment.
56
+ *
57
+ * @param property Non-geometric property targeted by the clause.
58
+ * @returns A CQL predicate fragment.
59
+ */
60
+ function compileIsNullClause(property) {
61
+ return `${property.name} IS NULL`;
62
+ }
63
+ /**
64
+ * Compiles a structured where clause into a CQL fragment.
65
+ *
66
+ * @param featureType Feature type definition loaded from the embedded catalog.
67
+ * @param geometryProperty Geometry property already resolved for the feature type.
68
+ * @param clause Raw where clause received from the tool input.
69
+ * @returns A CQL predicate fragment.
70
+ */
71
+ function compileWhereClause(featureType, geometryProperty, clause) {
72
+ const property = resolveNonGeometryProperty(featureType, geometryProperty, clause.property, "La propriété '{property}' est géométrique. Utiliser `spatial_operator` et ses paramètres dédiés.");
73
+ const normalized = normalizeWhereClause(property, clause);
74
+ switch (normalized.operator) {
75
+ case "eq":
76
+ case "ne":
77
+ return compileScalarComparisonClause(property, normalized);
78
+ case "lt":
79
+ case "lte":
80
+ case "gt":
81
+ case "gte":
82
+ return compileOrderedComparisonClause(property, normalized);
83
+ case "in":
84
+ return compileInClause(property, normalized);
85
+ case "is_null":
86
+ return compileIsNullClause(property);
87
+ }
88
+ }
89
+ /**
90
+ * Compiles a structured sort clause into a WFS `sortBy` fragment.
91
+ *
92
+ * @param featureType Feature type definition loaded from the embedded catalog.
93
+ * @param geometryProperty Geometry property already resolved for the feature type.
94
+ * @param clause Raw order-by clause received from the tool input.
95
+ * @returns A WFS `sortBy` fragment.
96
+ */
97
+ function compileOrderByClause(featureType, geometryProperty, clause) {
98
+ const property = resolveNonGeometryProperty(featureType, geometryProperty, clause.property, "La propriété '{property}' est géométrique. Utiliser une propriété non géométrique pour `order_by`.");
99
+ return `${property.name} ${ORDER_DIRECTION_TO_WFS[clause.direction]}`;
100
+ }
101
+ // --- Query Compilation ---
102
+ /**
103
+ * Compiles normalized tool input into query fragments ready to be turned into a WFS request.
104
+ *
105
+ * @param input Normalized tool input.
106
+ * @param featureType Feature type definition loaded from the embedded catalog.
107
+ * @param resolvedGeometryRef Optional resolved reference geometry for `intersects_feature`.
108
+ * @returns Compiled query parts used by request builders.
109
+ */
110
+ export function compileQueryParts(input, featureType, resolvedGeometryRef) {
111
+ const geometryProperty = getGeometryProperty(featureType);
112
+ const spatialFilter = getSpatialFilter(input);
113
+ const fragments = [];
114
+ // Keep the spatial predicate first: the GeoPlateforme GeoServer is sensitive
115
+ // to filter ordering and may reject equivalent filters when attributes come first.
116
+ if (spatialFilter) {
117
+ switch (spatialFilter.operator) {
118
+ case "bbox":
119
+ fragments.push(compileBboxSpatialFilter(geometryProperty, spatialFilter));
120
+ break;
121
+ case "intersects_point":
122
+ fragments.push(compileIntersectsPointSpatialFilter(geometryProperty, spatialFilter));
123
+ break;
124
+ case "dwithin_point":
125
+ fragments.push(compileDwithinSpatialFilter(geometryProperty, spatialFilter));
126
+ break;
127
+ case "intersects_feature":
128
+ if (!resolvedGeometryRef) {
129
+ throw new Error("Le filtre spatial `intersects_feature` exige la résolution préalable de la géométrie de référence.");
130
+ }
131
+ fragments.push(compileIntersectsFeatureSpatialFilter(geometryProperty, resolvedGeometryRef.geometry_ewkt));
132
+ break;
133
+ }
134
+ }
135
+ for (const clause of input.where ?? []) {
136
+ fragments.push(compileWhereClause(featureType, geometryProperty, clause));
137
+ }
138
+ const sortBy = input.order_by && input.order_by.length > 0
139
+ ? input.order_by.map((clause) => compileOrderByClause(featureType, geometryProperty, clause)).join(",")
140
+ : undefined;
141
+ const propertyNames = buildSelectList(featureType, geometryProperty, input);
142
+ return {
143
+ geometryProperty,
144
+ cqlFilter: fragments.length > 0 ? fragments.join(" AND ") : undefined,
145
+ propertyName: propertyNames.length > 0 ? propertyNames.join(",") : undefined,
146
+ sortBy,
147
+ };
148
+ }
149
+ //# sourceMappingURL=queryPreparation.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"queryPreparation.js","sourceRoot":"","sources":["../../../src/helpers/wfs_engine/queryPreparation.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAIH,OAAO,EAEL,eAAe,EACf,0BAA0B,EAC1B,mBAAmB,GACpB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAQtD,OAAO,EACL,iBAAiB,EACjB,oBAAoB,EACpB,2BAA2B,EAC3B,4BAA4B,GAC7B,MAAM,sBAAsB,CAAC;AAE9B,OAAO,EACL,wBAAwB,EACxB,2BAA2B,EAC3B,qCAAqC,EACrC,mCAAmC,GACpC,MAAM,iBAAiB,CAAC;AAEzB,qBAAqB;AAErB,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAC/C,OAAO,EAAE,sBAAsB,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AAC9E,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;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CAAC;AACJ,CAAC"}
@@ -1,20 +1,44 @@
1
+ /**
2
+ * WFS request builders used by the structured WFS engine.
3
+ *
4
+ * This module centralizes:
5
+ * - the transport shape shared by compiled requests
6
+ * - GET/POST request assembly helpers
7
+ * - the compact request payload exposed by MCP `result_type="request"`
8
+ */
1
9
  import type { GpfWfsGetFeaturesInput } from "./schema.js";
2
- export type CompiledRequest = {
10
+ type WfsRequestTransport = {
3
11
  method: "POST";
4
12
  url: string;
5
13
  query: Record<string, string>;
6
14
  body: string;
15
+ };
16
+ export type CompiledRequest = WfsRequestTransport & {
7
17
  get_url?: string | null;
8
18
  };
19
+ export type WfsRequestPayload = WfsRequestTransport & {
20
+ result_type: "request";
21
+ get_url: string | null;
22
+ };
23
+ /**
24
+ * Maps a compiled WFS request to the compact MCP request payload.
25
+ *
26
+ * @param request Compiled request ready to be executed against the WFS service.
27
+ * @returns A normalized request payload exposed by MCP tools.
28
+ */
29
+ export declare function toWfsRequestPayload(request: CompiledRequest): WfsRequestPayload;
9
30
  /**
10
31
  * Builds a portable GET URL variant of the request when it stays below the configured limit.
11
32
  *
33
+ * This helper is mainly used to populate `get_url` in request payloads
34
+ * returned by `result_type="request"`.
35
+ *
12
36
  * @param url Base WFS endpoint URL.
13
37
  * @param query Query-string parameters sent with the request.
14
38
  * @param cqlFilter Optional CQL filter to append to the GET variant.
15
39
  * @returns A derived GET URL, or `null` when it would be too long to expose safely.
16
40
  */
17
- export declare function buildGetUrl(url: string, query: Record<string, string>, cqlFilter?: string): string;
41
+ export declare function buildGetUrl(url: string, query: Record<string, string>, cqlFilter?: string): string | null;
18
42
  /**
19
43
  * Builds the main WFS GetFeature request from normalized tool input and compiled query parts.
20
44
  *
@@ -45,3 +69,26 @@ export declare function buildReferenceGeometryRequest(typename: string, featureI
45
69
  * @returns A POST request split into base URL, query-string parameters, empty body, and optional GET variant.
46
70
  */
47
71
  export declare function buildGetFeatureByIdRequest(typename: string, featureId: string, propertyName?: string): CompiledRequest;
72
+ /**
73
+ * Input parameters for building a multi-typename WFS request.
74
+ */
75
+ export type MultiTypenameRequestInput = {
76
+ /** Fully qualified WFS type names to query. */
77
+ typenames: string[];
78
+ /** Pre-compiled CQL filter string, when one shared filter is intentionally reused for all typenames. */
79
+ cqlFilter?: string;
80
+ /** Pre-compiled CQL filters aligned with `typenames` (same length, same order). */
81
+ cqlFilters?: string[];
82
+ };
83
+ /**
84
+ * Builds a WFS GetFeature request targeting multiple typenames.
85
+ *
86
+ * Unlike `buildMainRequest()`, this builder accepts a raw CQL filter
87
+ * and a list of typenames, making it suitable for domain-oriented modules
88
+ * that query several layers at once.
89
+ *
90
+ * @param input Multi-typename request parameters.
91
+ * @returns A POST request split into base URL, query-string parameters, encoded body, and optional GET variant.
92
+ */
93
+ export declare function buildMultiTypenameRequest(input: MultiTypenameRequestInput): CompiledRequest;
94
+ export {};
@@ -1,5 +1,31 @@
1
- import { GPF_WFS_URL } from "../../gpf/wfs.js";
1
+ /**
2
+ * WFS request builders used by the structured WFS engine.
3
+ *
4
+ * This module centralizes:
5
+ * - the transport shape shared by compiled requests
6
+ * - GET/POST request assembly helpers
7
+ * - the compact request payload exposed by MCP `result_type="request"`
8
+ */
9
+ import { GPF_WFS_URL } from "../../gpf/wfs-schema-catalog.js";
2
10
  import { REQUEST_GET_URL_MAX_LENGTH } from "./schema.js";
11
+ // --- Request Payload Mapping ---
12
+ /**
13
+ * Maps a compiled WFS request to the compact MCP request payload.
14
+ *
15
+ * @param request Compiled request ready to be executed against the WFS service.
16
+ * @returns A normalized request payload exposed by MCP tools.
17
+ */
18
+ export function toWfsRequestPayload(request) {
19
+ return {
20
+ result_type: "request",
21
+ method: request.method,
22
+ url: request.url,
23
+ query: request.query,
24
+ body: request.body,
25
+ get_url: request.get_url ?? null,
26
+ };
27
+ }
28
+ // --- Request Assembly Helpers ---
3
29
  /**
4
30
  * Encodes the optional CQL filter as an `application/x-www-form-urlencoded` POST body.
5
31
  *
@@ -15,6 +41,9 @@ function buildBody(cqlFilter) {
15
41
  /**
16
42
  * Builds a portable GET URL variant of the request when it stays below the configured limit.
17
43
  *
44
+ * This helper is mainly used to populate `get_url` in request payloads
45
+ * returned by `result_type="request"`.
46
+ *
18
47
  * @param url Base WFS endpoint URL.
19
48
  * @param query Query-string parameters sent with the request.
20
49
  * @param cqlFilter Optional CQL filter to append to the GET variant.
@@ -31,6 +60,7 @@ export function buildGetUrl(url, query, cqlFilter) {
31
60
  }
32
61
  return getUrl;
33
62
  }
63
+ // --- Public Builders ---
34
64
  /**
35
65
  * Builds the main WFS GetFeature request from normalized tool input and compiled query parts.
36
66
  *
@@ -45,6 +75,7 @@ export function buildMainRequest(input, compiled) {
45
75
  request: "GetFeature",
46
76
  typeNames: input.typename,
47
77
  outputFormat: "application/json",
78
+ exceptions: "application/json",
48
79
  count: input.result_type === "hits" ? "1" : String(input.limit),
49
80
  };
50
81
  if (compiled.propertyName && input.result_type !== "hits") {
@@ -77,6 +108,7 @@ export function buildReferenceGeometryRequest(typename, featureId, geometryPrope
77
108
  request: "GetFeature",
78
109
  typeNames: typename,
79
110
  outputFormat: "application/json",
111
+ exceptions: "application/json",
80
112
  featureID: featureId,
81
113
  propertyName: geometryPropertyName,
82
114
  count: "1",
@@ -104,6 +136,7 @@ export function buildGetFeatureByIdRequest(typename, featureId, propertyName) {
104
136
  request: "GetFeature",
105
137
  typeNames: typename,
106
138
  outputFormat: "application/json",
139
+ exceptions: "application/json",
107
140
  featureID: featureId,
108
141
  count: "2",
109
142
  };
@@ -118,4 +151,47 @@ export function buildGetFeatureByIdRequest(typename, featureId, propertyName) {
118
151
  get_url: buildGetUrl(GPF_WFS_URL, query),
119
152
  };
120
153
  }
154
+ /**
155
+ * Builds a WFS GetFeature request targeting multiple typenames.
156
+ *
157
+ * Unlike `buildMainRequest()`, this builder accepts a raw CQL filter
158
+ * and a list of typenames, making it suitable for domain-oriented modules
159
+ * that query several layers at once.
160
+ *
161
+ * @param input Multi-typename request parameters.
162
+ * @returns A POST request split into base URL, query-string parameters, encoded body, and optional GET variant.
163
+ */
164
+ export function buildMultiTypenameRequest(input) {
165
+ if (input.cqlFilter && input.cqlFilters) {
166
+ throw new Error("`cqlFilter` et `cqlFilters` ne peuvent pas être utilisés ensemble.");
167
+ }
168
+ if (input.cqlFilters && input.cqlFilters.length !== input.typenames.length) {
169
+ throw new Error(`Le nombre de filtres CQL (${input.cqlFilters.length}) doit correspondre au nombre de typenames (${input.typenames.length}).`);
170
+ }
171
+ const encodedTypeNames = input.typenames.map((typename) => `(${typename})`).join("");
172
+ const expandedCqlFilter = input.cqlFilters
173
+ ? input.cqlFilters.join(";")
174
+ : input.cqlFilter
175
+ ? input.typenames.map(() => input.cqlFilter).join(";")
176
+ : undefined;
177
+ const query = {
178
+ service: "WFS",
179
+ version: "2.0.0",
180
+ request: "GetFeature",
181
+ typeNames: encodedTypeNames,
182
+ outputFormat: "application/json",
183
+ exceptions: "application/json",
184
+ srsName: "EPSG:4326",
185
+ };
186
+ const body = expandedCqlFilter
187
+ ? new URLSearchParams({ cql_filter: expandedCqlFilter }).toString()
188
+ : "";
189
+ return {
190
+ method: "POST",
191
+ url: GPF_WFS_URL,
192
+ query,
193
+ body,
194
+ get_url: buildGetUrl(GPF_WFS_URL, query, expandedCqlFilter),
195
+ };
196
+ }
121
197
  //# sourceMappingURL=request.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"request.js","sourceRoot":"","sources":["../../../src/helpers/wfs_engine/request.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,iCAAiC,CAAC;AAE9D,OAAO,EAAE,0BAA0B,EAAE,MAAM,aAAa,CAAC;AAoBzD,kCAAkC;AAElC;;;;;GAKG;AACH,MAAM,UAAU,mBAAmB,CAAC,OAAwB;IAC1D,OAAO;QACL,WAAW,EAAE,SAAS;QACtB,MAAM,EAAE,OAAO,CAAC,MAAM;QACtB,GAAG,EAAE,OAAO,CAAC,GAAG;QAChB,KAAK,EAAE,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D,CAAC,CAAC,SAAS,CAAC;IAEhB,MAAM,KAAK,GAA2B;QACpC,OAAO,EAAE,KAAK;QACd,OAAO,EAAE,OAAO;QAChB,OAAO,EAAE,YAAY;QACrB,SAAS,EAAE,gBAAgB;QAC3B,YAAY,EAAE,kBAAkB;QAChC,UAAU,EAAE,kBAAkB;QAC9B,OAAO,EAAE,WAAW;KACrB,CAAC;IAEF,MAAM,IAAI,GAAG,iBAAiB;QAC5B,CAAC,CAAC,IAAI,eAAe,CAAC,EAAE,UAAU,EAAE,iBAAiB,EAAE,CAAC,CAAC,QAAQ,EAAE;QACnE,CAAC,CAAC,EAAE,CAAC;IAEP,OAAO;QACL,MAAM,EAAE,MAAM;QACd,GAAG,EAAE,WAAW;QAChB,KAAK;QACL,IAAI;QACJ,OAAO,EAAE,WAAW,CAAC,WAAW,EAAE,KAAK,EAAE,iBAAiB,CAAC;KAC5D,CAAC;AACJ,CAAC"}
@@ -0,0 +1,80 @@
1
+ /**
2
+ * Structured WFS response layer used by the MCP WFS tools and domain-oriented modules.
3
+ *
4
+ * This module provides:
5
+ * - FeatureCollection-preserving transformations for the MCP WFS tools
6
+ * - Flat item mapping for domain-oriented modules (`src/gpf/*`)
7
+ */
8
+ type GenericFeature = {
9
+ id?: unknown;
10
+ geometry?: unknown;
11
+ geometry_name?: string;
12
+ bbox?: unknown;
13
+ properties?: unknown;
14
+ [key: string]: unknown;
15
+ };
16
+ type GenericFeatureCollection = {
17
+ features?: GenericFeature[];
18
+ [key: string]: unknown;
19
+ };
20
+ type FeatureRef = {
21
+ typename: string | null;
22
+ feature_id: string;
23
+ };
24
+ type TransformedFeature = Record<string, unknown> & {
25
+ feature_ref?: FeatureRef;
26
+ };
27
+ type TransformedFeatureCollection = Record<string, unknown> & {
28
+ features?: TransformedFeature[];
29
+ };
30
+ /**
31
+ * A flattened WFS feature with properties spread at the top level.
32
+ *
33
+ * This is the output format used by domain-oriented modules (`src/gpf/*`)
34
+ * as opposed to the FeatureCollection-preserving format used by the MCP WFS tools.
35
+ */
36
+ export type FlatItem = Record<string, unknown> & {
37
+ type: string;
38
+ id: string;
39
+ bbox?: number[];
40
+ feature_ref?: {
41
+ typename: string;
42
+ feature_id: string;
43
+ };
44
+ };
45
+ /**
46
+ * Removes raw geometry payloads from a FeatureCollection, keeps GeoJSON validity by forcing
47
+ * `geometry: null`, and exposes lightweight `feature_ref` objects reusable by follow-up requests.
48
+ *
49
+ * @param featureCollection Raw FeatureCollection returned by the WFS endpoint.
50
+ * @returns A transformed FeatureCollection with raw geometry fields removed, `geometry: null`, and optional `feature_ref` metadata.
51
+ */
52
+ export declare function transformFeatureCollectionResponse(featureCollection: GenericFeatureCollection): TransformedFeatureCollection;
53
+ /**
54
+ * Transforms a FeatureCollection and injects the exact queried typename into each `feature_ref`.
55
+ *
56
+ * @param featureCollection Raw FeatureCollection returned by the WFS endpoint.
57
+ * @param typename Typename of the queried layer.
58
+ * @returns A transformed FeatureCollection whose `feature_ref` objects carry the exact typename.
59
+ */
60
+ export declare function attachFeatureRefs(featureCollection: GenericFeatureCollection, typename: string): TransformedFeatureCollection;
61
+ /**
62
+ * Maps a FeatureCollection to an array of flat items without preserving geometry.
63
+ *
64
+ * @param featureCollection Raw FeatureCollection returned by the WFS endpoint.
65
+ * @param knownTypeNames Fully qualified typenames used for `feature_ref` resolution.
66
+ * @returns An array of flat items with spread properties and `feature_ref`.
67
+ */
68
+ export declare function mapToFlatItems(featureCollection: GenericFeatureCollection, knownTypeNames: string[]): FlatItem[];
69
+ /**
70
+ * Maps a FeatureCollection to an array of flat items preserving raw geometry
71
+ * in a temporary `_rawGeometry` field for downstream distance calculations.
72
+ *
73
+ * Callers should strip `_rawGeometry` from the final output.
74
+ *
75
+ * @param featureCollection Raw FeatureCollection returned by the WFS endpoint.
76
+ * @param knownTypeNames Fully qualified typenames used for `feature_ref` resolution.
77
+ * @returns An array of flat items with `_rawGeometry` preserved.
78
+ */
79
+ export declare function mapToFlatItemsWithGeometry(featureCollection: GenericFeatureCollection, knownTypeNames: string[]): FlatItem[];
80
+ export {};
@@ -0,0 +1,135 @@
1
+ /**
2
+ * Structured WFS response layer used by the MCP WFS tools and domain-oriented modules.
3
+ *
4
+ * This module provides:
5
+ * - FeatureCollection-preserving transformations for the MCP WFS tools
6
+ * - Flat item mapping for domain-oriented modules (`src/gpf/*`)
7
+ */
8
+ // --- Response Transformation ---
9
+ /**
10
+ * Removes raw geometry payloads from a FeatureCollection, keeps GeoJSON validity by forcing
11
+ * `geometry: null`, and exposes lightweight `feature_ref` objects reusable by follow-up requests.
12
+ *
13
+ * @param featureCollection Raw FeatureCollection returned by the WFS endpoint.
14
+ * @returns A transformed FeatureCollection with raw geometry fields removed, `geometry: null`, and optional `feature_ref` metadata.
15
+ */
16
+ export function transformFeatureCollectionResponse(featureCollection) {
17
+ if (!Array.isArray(featureCollection.features)) {
18
+ return featureCollection;
19
+ }
20
+ const transformedFeatures = featureCollection.features.map((feature) => {
21
+ const { geometry: _geometry, geometry_name: _geometryName, ...rest } = feature;
22
+ const nextFeature = {
23
+ ...rest,
24
+ geometry: null,
25
+ };
26
+ if (typeof feature.id === "string") {
27
+ nextFeature.feature_ref = {
28
+ typename: null,
29
+ feature_id: feature.id,
30
+ };
31
+ }
32
+ return nextFeature;
33
+ });
34
+ const { crs: _crs, ...restCollection } = featureCollection;
35
+ return { ...restCollection, features: transformedFeatures };
36
+ }
37
+ // --- Feature References ---
38
+ /**
39
+ * Transforms a FeatureCollection and injects the exact queried typename into each `feature_ref`.
40
+ *
41
+ * @param featureCollection Raw FeatureCollection returned by the WFS endpoint.
42
+ * @param typename Typename of the queried layer.
43
+ * @returns A transformed FeatureCollection whose `feature_ref` objects carry the exact typename.
44
+ */
45
+ export function attachFeatureRefs(featureCollection, typename) {
46
+ const transformed = transformFeatureCollectionResponse(featureCollection);
47
+ if (!Array.isArray(transformed.features)) {
48
+ return transformed;
49
+ }
50
+ transformed.features = transformed.features.map((feature) => {
51
+ if (!("feature_ref" in feature)) {
52
+ return feature;
53
+ }
54
+ const featureRef = feature.feature_ref;
55
+ if (typeof featureRef !== "object" || featureRef === null) {
56
+ return feature;
57
+ }
58
+ return {
59
+ ...feature,
60
+ feature_ref: {
61
+ ...featureRef,
62
+ typename,
63
+ },
64
+ };
65
+ });
66
+ return transformed;
67
+ }
68
+ // --- Flat Item Mapping ---
69
+ /**
70
+ * Resolves the fully qualified typename from a feature id prefix and a list of known typenames.
71
+ *
72
+ * @param featureId Feature id (e.g. `"commune.8952"`).
73
+ * @param knownTypeNames Fully qualified typenames to match against.
74
+ * @returns The matching typename, or `undefined`.
75
+ */
76
+ function resolveTypename(featureId, knownTypeNames) {
77
+ const featureType = featureId.split(".")[0];
78
+ return knownTypeNames.find((candidate) => candidate.endsWith(`:${featureType}`));
79
+ }
80
+ /**
81
+ * Maps a single WFS feature to a flat item with spread properties and optional `feature_ref`.
82
+ *
83
+ * @param feature Raw WFS feature from the response.
84
+ * @param knownTypeNames Fully qualified typenames used for `feature_ref` resolution.
85
+ * @returns A flat item with type, id, bbox, optional feature_ref, and spread properties.
86
+ */
87
+ function mapFeatureToFlatItem(feature, knownTypeNames) {
88
+ const { properties, id, bbox, geometry: _geometry, geometry_name: _geometryName, ...rest } = feature;
89
+ const featureId = typeof id === "string" ? id : "unknown";
90
+ const typename = resolveTypename(featureId, knownTypeNames);
91
+ return {
92
+ ...(properties ?? {}),
93
+ ...rest,
94
+ type: featureId.split(".")[0],
95
+ id: featureId,
96
+ ...(bbox ? { bbox: bbox } : {}),
97
+ ...(typename ? { feature_ref: { typename, feature_id: featureId } } : {}),
98
+ };
99
+ }
100
+ /**
101
+ * Maps a FeatureCollection to an array of flat items without preserving geometry.
102
+ *
103
+ * @param featureCollection Raw FeatureCollection returned by the WFS endpoint.
104
+ * @param knownTypeNames Fully qualified typenames used for `feature_ref` resolution.
105
+ * @returns An array of flat items with spread properties and `feature_ref`.
106
+ */
107
+ export function mapToFlatItems(featureCollection, knownTypeNames) {
108
+ if (!Array.isArray(featureCollection.features)) {
109
+ return [];
110
+ }
111
+ return featureCollection.features.map((feature) => mapFeatureToFlatItem(feature, knownTypeNames));
112
+ }
113
+ /**
114
+ * Maps a FeatureCollection to an array of flat items preserving raw geometry
115
+ * in a temporary `_rawGeometry` field for downstream distance calculations.
116
+ *
117
+ * Callers should strip `_rawGeometry` from the final output.
118
+ *
119
+ * @param featureCollection Raw FeatureCollection returned by the WFS endpoint.
120
+ * @param knownTypeNames Fully qualified typenames used for `feature_ref` resolution.
121
+ * @returns An array of flat items with `_rawGeometry` preserved.
122
+ */
123
+ export function mapToFlatItemsWithGeometry(featureCollection, knownTypeNames) {
124
+ if (!Array.isArray(featureCollection.features)) {
125
+ return [];
126
+ }
127
+ return featureCollection.features.map((feature) => {
128
+ const flatItem = mapFeatureToFlatItem(feature, knownTypeNames);
129
+ return {
130
+ ...flatItem,
131
+ _rawGeometry: feature.geometry ?? null,
132
+ };
133
+ });
134
+ }
135
+ //# sourceMappingURL=response.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"response.js","sourceRoot":"","sources":["../../../src/helpers/wfs_engine/response.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AA4CH,kCAAkC;AAElC;;;;;;GAMG;AACH,MAAM,UAAU,kCAAkC,CAChD,iBAA2C;IAE3C,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,iBAAiB,CAAC,QAAQ,CAAC,EAAE,CAAC;QAC/C,OAAO,iBAAiB,CAAC;IAC3B,CAAC;IAED,MAAM,mBAAmB,GAAG,iBAAiB,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE;QACrE,MAAM,EAAE,QAAQ,EAAE,SAAS,EAAE,aAAa,EAAE,aAAa,EAAE,GAAG,IAAI,EAAE,GAAG,OAAO,CAAC;QAE/E,MAAM,WAAW,GAA4B;YAC3C,GAAG,IAAI;YACP,QAAQ,EAAE,IAAI;SACf,CAAC;QAEF,IAAI,OAAO,OAAO,CAAC,EAAE,KAAK,QAAQ,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