Skip to content

Commit ed43065

Browse files
authored
Merge branch 'main' into feature/address-search-title-i18n
2 parents da91743 + c0f41ac commit ed43065

File tree

9 files changed

+104
-93
lines changed

9 files changed

+104
-93
lines changed

package-lock.json

Lines changed: 42 additions & 42 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/clients/dish/src/utils/navigateToDenkmal.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ export function navigateToDenkmal(instance, objektId: string) {
1111
if (!wfsConfig) {
1212
throw new Error('Client is missing wfsConfig on DISH search method.')
1313
}
14+
if (!wfsConfig.queryParameters) {
15+
throw new Error(
16+
'Client is missing wfsConfig.queryParameters on DISH search method.'
17+
)
18+
}
1419

1520
getWfsFeatures(null, denkmaelerWfsService.url, objektId, {
1621
...wfsConfig.queryParameters.wfsConfiguration,

packages/lib/getFeatures/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# CHANGELOG
22

3+
## unpublished
4+
5+
- Breaking: `getWfsFeatures` now throws errors if required parameters on the wfs configuration are missing instead of only printing error messages on the console.
6+
37
## 1.0.1
48

59
- Fix: Increase type precision of EPSG codes from `string` to `EPSG:${string}`.

packages/lib/getFeatures/gazetteer/parse.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ export function parseGazetteerResponse(
2424
const gmlFeatures = new DOMParser()
2525
.parseFromString(text, 'application/xml')
2626
.getElementsByTagName(`wfs:${memberSuffix}`)
27-
// @ts-expect-error | This is needed as this already is a workaround because the GeoJSON reader can't read the XMLResponse from a WFS-G
2827
const featureCollection: FeatureCollection = {
2928
type: 'FeatureCollection',
3029
features,

packages/lib/getFeatures/types.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,20 @@ export interface AdditionalSearchOptions {
1212
typeNames?: string | string[]
1313
}
1414

15+
/*
16+
* Explanation by dimension:
17+
* First: each child resembles a query
18+
* Second: children will be ANDed on multiple children
19+
* Third: [key, value] where key is a property name
20+
* Explanation by example:
21+
* [[['a', 'b'], ['a', 'c']], [['a', 'b']]]
22+
* becomes
23+
* QUERY(a=b && c=d), QUERY(a=b)
24+
* where the second query is only executed if the first doesn't fill
25+
* maxFeatures to its limit.
26+
*/
27+
export type KeyValueSetArray = Array<Array<[string, string]>>
28+
1529
/** Adds the possibility to have a 'title' attribute in a GeoJSON Feature */
1630
export interface PolarGeoJsonFeature extends GeoJsonFeature {
1731
/** The projection of the coordinates of the features */

packages/lib/getFeatures/wfs/buildWfsFilter.ts

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { WfsParameters } from '../types'
1+
import { KeyValueSetArray, WfsParameters } from '../types'
22

33
const removeLinebreaks = (s) => s.replace(/\r?\n|\r/g, '')
44

@@ -58,21 +58,10 @@ const buildWfsFilterQuery = (
5858
* Builds filter of multiple queries from possible interpretations of inputs.
5959
* Multiple queries are sent so that service may stop computing after
6060
* maxFeatures has been fulfilled.
61-
* @param inputs - Explanation by dimension.
62-
* First: each child resembles a query
63-
* Second: children will be ANDed on multiple children
64-
* Third: [key, value] where key is a property name
65-
* Explanation by example.
66-
* [[['a', 'b'], ['a', 'c']], [['a', 'b']]]
67-
* becomes
68-
* QUERY(a=b && c=d), QUERY(a=b)
69-
* where the second query is only executed if the first doesn't fill
70-
* maxFeatures to its limit.
71-
* @param parameters - @see WfsParameters
7261
* @returns request xml
7362
*/
7463
export const buildWfsFilter = (
75-
inputs: Array<Array<[string, string]>>,
64+
inputs: KeyValueSetArray,
7665
parameters: WfsParameters
7766
) =>
7867
removeLinebreaks(

packages/lib/getFeatures/wfs/getFeatureTitleFromPattern.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ export const getFeatureTitleFromPattern = (
2828
const keys = blocks.reduce(
2929
(keyAccumulator, block) =>
3030
Array.isArray(block) ? [...keyAccumulator, block[1]] : keyAccumulator,
31-
[]
32-
) as string[]
31+
[] as string[]
32+
)
3333
const foundKeys = keys.reduce(
3434
(sum, key) =>
3535
typeof properties[key] !== 'undefined' && properties[key] !== ''

packages/lib/getFeatures/wfs/index.ts

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,34 @@
1-
import { WfsParameters } from '../types'
1+
import { KeyValueSetArray, WfsParameters } from '../types'
22
import { errorCheck } from '../utils/errorCheck'
33
import { parseWfsResponse } from './parse'
44
import { buildWfsFilter } from './buildWfsFilter'
55
import { match } from './match'
66

7-
export function getWfsFeatures(
7+
export async function getWfsFeatures(
88
signal: AbortSignal | null,
99
url: string,
1010
inputValue: string,
1111
parameters: WfsParameters
1212
) {
1313
const { fieldName, patterns, patternKeys } = parameters
14-
// arrays OF sets OF key-value-pairs
15-
let inputs: string[][][] = [[[]]]
16-
17-
if (fieldName && patterns) {
18-
console.error(
19-
'@polar/lib-get-features: Using both fieldName and patterns for WFS search. These are mutually exclusive. Patterns will be ignored.'
14+
if (!fieldName && (!patterns || !patternKeys)) {
15+
throw new Error(
16+
'Incomplete WFS search configuration. Either "fieldName" or "patterns" and "patternKeys" are required.'
2017
)
2118
}
22-
23-
if (fieldName) {
24-
inputs = [[[fieldName, inputValue]]]
25-
} else if (patterns && patternKeys) {
26-
inputs = match(patterns, patternKeys, inputValue)
27-
} else {
19+
if (fieldName && patterns) {
2820
console.error(
29-
'@polar/lib-get-features: Incomplete WFS search configuration. Either "fieldName" or "patterns" and "patternKeys" are required.'
21+
'@polar/lib-get-features: Using both fieldName and patterns for WFS search. These are mutually exclusive. Patterns will be ignored.'
3022
)
3123
}
24+
// arrays of sets of key-value-pairs
25+
const inputs: KeyValueSetArray = fieldName
26+
? [[[fieldName, inputValue]]]
27+
: match(patterns, patternKeys, inputValue)
3228

3329
const body = buildWfsFilter(inputs, parameters)
3430

35-
return fetch(encodeURI(url), { signal, method: 'POST', body }).then(
36-
(response: Response) => {
37-
errorCheck(response)
38-
return parseWfsResponse(response, fieldName || patterns, !fieldName)
39-
}
40-
)
31+
const response = await fetch(encodeURI(url), { signal, method: 'POST', body })
32+
errorCheck(response)
33+
return parseWfsResponse(response, fieldName || patterns, !fieldName)
4134
}

0 commit comments

Comments
 (0)