@data-fair/catalog-onegeo-suite 0.1.1 → 0.1.2

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.
package/lib/imports.ts CHANGED
@@ -154,7 +154,7 @@ export const getResource = async ({ catalogConfig, importConfig, resourceId, tmp
154
154
  },
155
155
  keywords: catalog._source['metadata-fr'].keyword,
156
156
  updatedAt: catalog._source['metadata-fr'].lastUpdateDate ?? undefined,
157
- image: catalog._source['metadata-fr'].image.find((x: { type: string, url: string | null }) => { return x.type === 'thumbnail' && !!x.url }).url ?? null,
157
+ image: catalog._source['metadata-fr'].image.find((x: { type: string, url: string | null }) => { return x.type === 'thumbnail' && !!x.url })?.url ?? null,
158
158
  origin
159
159
  }
160
160
  }
package/lib/list.ts CHANGED
@@ -10,6 +10,21 @@ const formatsList = [
10
10
  'CSV', 'ODS', 'Excel non structuré', 'Microsoft Excel',
11
11
  'ZIP', 'Shapefile (zip)', 'SHAPE-ZIP', 'GeoJSON', 'JSON', 'XML', 'GML', 'KML']
12
12
 
13
+ const extensionTable: Record<string, string> = {
14
+ CSV: '.csv',
15
+ GeoJSON: '.geojson',
16
+ JSON: '.json',
17
+ 'Shapefile (zip)': '.zip',
18
+ 'SHAPE-ZIP': '.zip',
19
+ ZIP: '.zip',
20
+ GML: '.gml',
21
+ KML: '.kml',
22
+ XML: '.xml',
23
+ ODS: '.ods',
24
+ 'Excel non structuré': '.xlsx',
25
+ 'Microsoft Excel': '.xls',
26
+ }
27
+
13
28
  const getBestFormat = (formats: string[]) => {
14
29
  return [...formats].sort((a, b) =>
15
30
  (formatsList.indexOf(a) === -1 ? formatsList.length : formatsList.indexOf(a)) -
@@ -58,7 +73,7 @@ const baseReqDataset = (input: string = '*', size: number = 50, from: number = 1
58
73
  export const list = async ({ catalogConfig, params }: ListContext<OneGeoSuiteConfig, OneGeoCapabilities>): ReturnType<CatalogPlugin['list']> => {
59
74
  const url = catalogConfig.url
60
75
  const listResources = async (params: Record<any, any>) => {
61
- let catalogs = (await axios.post(new URL('fr/indexer/elastic/_search/', url).href, baseReqDataset(params.q, params.size, params.page))).data
76
+ let catalogs = (await axios.post(new URL('fr/indexer/elastic/_search/', url).href, baseReqDataset(params.q ? '*' : params.q, params.size, params.page))).data
62
77
  const count = catalogs.hits.total.value
63
78
  catalogs = catalogs.hits.hits
64
79
  const res = []
@@ -78,11 +93,21 @@ export const list = async ({ catalogConfig, params }: ListContext<OneGeoSuiteCon
78
93
  return apiList.indexOf(x.service) - apiList.indexOf(y.service)
79
94
  })
80
95
 
96
+ const formatsSet: Set<string> = new Set()
97
+
98
+ for (const source of sources) {
99
+ for (const format of source.formats) {
100
+ if (formatsList.includes(format)) formatsSet.add(format)
101
+ }
102
+ }
103
+ let formats = (new Array(...formatsSet)).sort((a: string, b: string) => { return formatsList.indexOf(a) - formatsList.indexOf(b) })
104
+ formats = formats.map(x => extensionTable[x]?.slice(1) ?? x)
105
+
81
106
  res.push({
82
107
  id: `${catalog._id}`,
83
108
  title: catalog._source['metadata-fr'].title,
84
109
  description: sources[0].description,
85
- format: '',
110
+ format: formats.slice(0, 3).join(', ') + (formats.length ? '..' : ''),
86
111
  type: 'resource'
87
112
  } as ResourceList[number])
88
113
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@data-fair/catalog-onegeo-suite",
3
3
  "description": "OneGeoSuite plugin for the Data Fair catalogs service.",
4
- "version": "0.1.1",
4
+ "version": "0.1.2",
5
5
  "main": "index.ts",
6
6
  "type": "module",
7
7
  "scripts": {
@@ -32,7 +32,7 @@ export const schema = {
32
32
  "layout": {
33
33
  "cols": 6,
34
34
  "getItems": {
35
- "url": "${context.catalogConfig}/fr/indexer/elastic/_search/?q=_id:${context.resourceId}",
35
+ "url": "${context.catalogConfig.url}/fr/indexer/elastic/_search/?q=_id:${context.resourceId}",
36
36
  "itemsResults": "(function() { const links = data.hits.hits[0]._source['metadata-fr'].link; return links.filter(l => l.formats.find(f => ['CSV', 'ODS', 'Excel non structuré', 'Microsoft Excel','ZIP', 'Shapefile (zip)', 'GeoJSON', 'JSON', 'XML', 'GML', 'KML'].includes(f)) || ['WS', 'AFS', 'WFS'].includes(l.service)).map((l, i) => [l, i] ); })()",
37
37
  "itemTitle": "item[0].service?? 'Local N°' + (item[1] + 1)",
38
38
  "itemValue": "item[0].service?? item[0].url"
@@ -46,7 +46,7 @@ export const schema = {
46
46
  "if": "parent.data.service != null",
47
47
  "cols": 6,
48
48
  "getItems": {
49
- "url": "${context.catalogConfig}/fr/indexer/elastic/_search/?q=${parent.data.service}&q=_id:${context.resourceId}",
49
+ "url": "${context.catalogConfig.url}/fr/indexer/elastic/_search/?q=${parent.data.service}&q=_id:${context.resourceId}",
50
50
  "itemsResults": "(function(){const service = data.hits.hits[0]._source['metadata-fr'].link.find(x => x.service === parent.data.service || x.url === parent.data.service); let formats = service.formats; if (['WS', 'WFS', 'AFS'].includes(service.service) && !formats.includes('CSV')) {formats.push('CSV');} return formats; })()"
51
51
  }
52
52
  }
@@ -24,7 +24,7 @@
24
24
  "layout": {
25
25
  "cols": 6,
26
26
  "getItems": {
27
- "url": "${context.catalogConfig}/fr/indexer/elastic/_search/?q=_id:${context.resourceId}",
27
+ "url": "${context.catalogConfig.url}/fr/indexer/elastic/_search/?q=_id:${context.resourceId}",
28
28
  "itemsResults": "(function() { const links = data.hits.hits[0]._source['metadata-fr'].link; return links.filter(l => l.formats.find(f => ['CSV', 'ODS', 'Excel non structuré', 'Microsoft Excel','ZIP', 'Shapefile (zip)', 'GeoJSON', 'JSON', 'XML', 'GML', 'KML'].includes(f)) || ['WS', 'AFS', 'WFS'].includes(l.service)).map((l, i) => [l, i] ); })()",
29
29
  "itemTitle": "item[0].service?? 'Local N°' + (item[1] + 1)",
30
30
  "itemValue": "item[0].service?? item[0].url"
@@ -38,7 +38,7 @@
38
38
  "if": "parent.data.service != null",
39
39
  "cols": 6,
40
40
  "getItems": {
41
- "url": "${context.catalogConfig}/fr/indexer/elastic/_search/?q=${parent.data.service}&q=_id:${context.resourceId}",
41
+ "url": "${context.catalogConfig.url}/fr/indexer/elastic/_search/?q=${parent.data.service}&q=_id:${context.resourceId}",
42
42
  "itemsResults": "(function(){const service = data.hits.hits[0]._source['metadata-fr'].link.find(x => x.service === parent.data.service || x.url === parent.data.service); let formats = service.formats; if (['WS', 'WFS', 'AFS'].includes(service.service) && !formats.includes('CSV')) {formats.push('CSV');} return formats; })()"
43
43
  }
44
44
  }