From 748423f7acdb8bbf8dbb8148ad6dabe3c6086cc2 Mon Sep 17 00:00:00 2001 From: Kevin Fabre Date: Fri, 30 Aug 2024 18:05:12 +0200 Subject: [PATCH] feat(types): update and add new dataset types --- packages/api-client/src/client/constants.ts | 45 +++++++++++ packages/api-client/src/client/types.ts | 89 +++++++++------------ packages/api-client/src/index.ts | 1 + 3 files changed, 86 insertions(+), 49 deletions(-) create mode 100644 packages/api-client/src/client/constants.ts diff --git a/packages/api-client/src/client/constants.ts b/packages/api-client/src/client/constants.ts new file mode 100644 index 000000000..73bb1655d --- /dev/null +++ b/packages/api-client/src/client/constants.ts @@ -0,0 +1,45 @@ +export const ODS_DATASET_FIELD_TYPE = { + TEXT: "text", + INT : "int", + DOUBLE : "double", + BOOLEAN : "boolean", + GEO_SHAPE : "geo_shape", + DATETIME : "datetime", + DATE : "date", + IMAGE : "image", + FILE : "file", + JSON : "json", +} as const; + +export const EXPORT_DATASET_FORMAT = { + JSON: 'json', + GEOJSON: 'geojson', + SHP: 'shp', + CSV: 'csv', + XLSX: 'xlsx', + KML: 'kml', + JSONLD: 'jsonld', + JSONL: 'jsonl', + RDFXML: 'rdfxml', + TURTLE: 'turtle', + N3: 'n3', + MVT: 'mvt', +} as const; + +export const EXPORT_CATALOG_FORMAT = { + CSV: 'csv', + JSON: 'json', + XLSX: 'xlsx', + RDF: 'rdf', + TTL: 'ttl', + DATA_JSON: 'data.json', + RSS: 'rss', + DCAT: 'dcat', + DCAT_AP_CH: 'dcat-ap-ch', + DCAT_AP_IT: 'dcat-ap-it', + DCAT_AP_DE: 'dcat-ap-de', + DCAT_AP_SE: 'dcat-ap-se', + DCAT_AP_SP: 'dcat-ap-sp', + DCAT_AP_V1: 'dcat-ap-v1', + DCAT_AP_BENAP: 'dcat_ap_benap', +} as const; diff --git a/packages/api-client/src/client/types.ts b/packages/api-client/src/client/types.ts index 2c102dbfe..3cd992c71 100644 --- a/packages/api-client/src/client/types.ts +++ b/packages/api-client/src/client/types.ts @@ -1,5 +1,7 @@ // Type hints for Api response +import { EXPORT_CATALOG_FORMAT, EXPORT_DATASET_FORMAT, ODS_DATASET_FIELD_TYPE } from "./constants"; + export interface Facet { name: string; count: number; @@ -18,22 +20,40 @@ export interface Link { rel: string; } -export interface OdsDataset { - dataset_id?: string; - dataset_uid?: string; - has_records?: boolean; - data_visible?: boolean; - features?: string[]; +export type OdsDatasetFieldType = typeof ODS_DATASET_FIELD_TYPE[keyof typeof ODS_DATASET_FIELD_TYPE]; + +export interface OdsDatasetAttachement { + id: string; + mimetype: string; + title: string; + url: string; +} + +export interface OdsDatasetAlternativeExport extends OdsDatasetAttachement { + description: string; +} + +export interface OdsDatasetField { + description: string | null; + name: string; + label: string; + type: OdsDatasetFieldType; // eslint-disable-next-line @typescript-eslint/no-explicit-any - metas?: Record; - fields?: { - name?: string; - label?: string; - type?: string; - // eslint-disable-next-line @typescript-eslint/no-explicit-any - annotations?: any; - description?: string; - }[]; + annotations: any; +} + +export interface OdsDataset { + dataset_id: string; + dataset_uid: string; + has_records: boolean; + data_visible: boolean; + features: string[]; + // eslint-disable-next-line @typescript-eslint/no-explicit-any + metas: Record; + fields: OdsDatasetField[]; + visibility: 'restricted' | 'domain'; + attachements: OdsDatasetAttachement[] + alternative_exports: OdsDatasetAlternativeExport[] } export interface OdsRecord { @@ -68,41 +88,12 @@ export interface ApiQuery { export interface ApiExport { [key: string]: T; } -export const EnumExportCatalogFormat = { - CSV: 'csv', - JSON: 'json', - XLSX: 'xlsx', - RDF: 'rdf', - TTL: 'ttl', - DATA_JSON: 'data.json', - RSS: 'rss', - DCAT: 'dcat', - DCAT_AP_CH: 'dcat-ap-ch', - DCAT_AP_IT: 'dcat-ap-it', - DCAT_AP_DE: 'dcat-ap-de', - DCAT_AP_SE: 'dcat-ap-se', - DCAT_AP_SP: 'dcat-ap-sp', - DCAT_AP_V1: 'dcat-ap-v1', - DCAT_AP_BENAP: 'dcat_ap_benap', -} as const; + export type ExportCatalogFormat = - typeof EnumExportCatalogFormat[keyof typeof EnumExportCatalogFormat]; - -export const EnumExportDatasetFormat = { - JSON: 'json', - GEOJSON: 'geojson', - SHP: 'shp', - CSV: 'csv', - XLSX: 'xlsx', - KML: 'kml', - JSONLD: 'jsonld', - JSONL: 'jsonl', - RDFXML: 'rdfxml', - TURTLE: 'turtle', - N3: 'n3', - MVT: 'mvt', -} as const; + typeof EXPORT_CATALOG_FORMAT[keyof typeof EXPORT_CATALOG_FORMAT]; + + export type ExportDatasetFormat = - typeof EnumExportDatasetFormat[keyof typeof EnumExportDatasetFormat]; + typeof EXPORT_DATASET_FORMAT[keyof typeof EXPORT_DATASET_FORMAT]; diff --git a/packages/api-client/src/index.ts b/packages/api-client/src/index.ts index 007f46220..f6672716a 100644 --- a/packages/api-client/src/index.ts +++ b/packages/api-client/src/index.ts @@ -6,5 +6,6 @@ export * from './client'; export * from './client/error'; export * from './client/types'; +export * from './client/constants'; export * from './odsql'; export * from './odsql/clauses';