11// Type hints for Api response
22
3+ import { ValueOf } from '../utils' ;
4+ import { EXPORT_CATALOG_FORMAT , EXPORT_DATASET_FORMAT , ODS_DATASET_FIELD_TYPE } from './constants' ;
5+
36export interface Facet {
47 name : string ;
58 count : number ;
@@ -18,91 +21,65 @@ export interface Link {
1821 rel : string ;
1922}
2023
21- export interface OdsDataset {
22- dataset_id ?: string ;
23- dataset_uid ?: string ;
24- has_records ?: boolean ;
25- data_visible ?: boolean ;
26- features ?: string [ ] ;
27- // eslint-disable-next-line @typescript-eslint/no-explicit-any
28- metas ?: Record < string , any > ;
29- fields ?: {
30- name ?: string ;
31- label ?: string ;
32- type ?: string ;
33- // eslint-disable-next-line @typescript-eslint/no-explicit-any
34- annotations ?: any ;
35- description ?: string ;
36- } [ ] ;
24+ interface DataWithLinks {
25+ _links ?: Link [ ] ;
3726}
3827
39- export interface OdsRecord < T > {
40- id ?: string ;
41- timestamp ?: string ;
42- size ?: number ;
43- fields : T ;
28+ export type DatasetFieldType = ValueOf < typeof ODS_DATASET_FIELD_TYPE > ;
29+
30+ export interface DatasetAttachement {
31+ id : string ;
32+ mimetype : string ;
33+ title : string ;
34+ url : string ;
4435}
4536
46- export interface ApiRecords < T > {
47- total_count ?: number ;
48- links : Link [ ] ;
49- results : OdsRecord < T > [ ] ;
37+ export interface DatasetAlternativeExport extends DatasetAttachement {
38+ description : string ;
5039}
5140
52- export interface ApiDatasets {
53- total_count : number ;
54- links : Link [ ] ;
55- results : OdsDataset [ ] ;
41+ export interface DatasetField {
42+ description : string | null ;
43+ name : string ;
44+ label : string ;
45+ type : DatasetFieldType ;
46+ annotations : unknown ;
5647}
5748
49+ export type Dataset = DataWithLinks & {
50+ dataset_id : string ;
51+ dataset_uid : string ;
52+ has_records : boolean ;
53+ data_visible : boolean ;
54+ features : string [ ] ;
55+ metas : object ;
56+ fields : DatasetField [ ] ;
57+ visibility : 'restricted' | 'domain' ;
58+ attachements : DatasetAttachement [ ] ;
59+ alternative_exports : DatasetAlternativeExport [ ] ;
60+ } ;
61+
62+ export type DatasetRecord < T extends object > = T & DataWithLinks ;
63+
5864export interface ApiFacets {
5965 links : Link [ ] ;
6066 facets : FacetRoot [ ] ;
6167}
6268
63- export interface ApiQuery < T > {
69+ export type ApiQuery < T extends object > = DataWithLinks & {
6470 total_count ?: number ;
6571 results : T [ ] ;
66- }
72+ } ;
73+
74+ export type ApiCatalog < Shape extends object = Dataset > = ApiQuery < Shape > & { total_count : number } ;
75+ export type ApiDatasetRecords < R extends object > = ApiQuery < DatasetRecord < R > > & {
76+ total_count : number ;
77+ } ;
6778
6879export interface ApiExport < T > {
6980 [ key : string ] : T ;
7081}
71- export const EnumExportCatalogFormat = {
72- CSV : 'csv' ,
73- JSON : 'json' ,
74- XLSX : 'xlsx' ,
75- RDF : 'rdf' ,
76- TTL : 'ttl' ,
77- DATA_JSON : 'data.json' ,
78- RSS : 'rss' ,
79- DCAT : 'dcat' ,
80- DCAT_AP_CH : 'dcat-ap-ch' ,
81- DCAT_AP_IT : 'dcat-ap-it' ,
82- DCAT_AP_DE : 'dcat-ap-de' ,
83- DCAT_AP_SE : 'dcat-ap-se' ,
84- DCAT_AP_SP : 'dcat-ap-sp' ,
85- DCAT_AP_V1 : 'dcat-ap-v1' ,
86- DCAT_AP_BENAP : 'dcat_ap_benap' ,
87- } as const ;
88-
89- export type ExportCatalogFormat =
90- typeof EnumExportCatalogFormat [ keyof typeof EnumExportCatalogFormat ] ;
91-
92- export const EnumExportDatasetFormat = {
93- JSON : 'json' ,
94- GEOJSON : 'geojson' ,
95- SHP : 'shp' ,
96- CSV : 'csv' ,
97- XLSX : 'xlsx' ,
98- KML : 'kml' ,
99- JSONLD : 'jsonld' ,
100- JSONL : 'jsonl' ,
101- RDFXML : 'rdfxml' ,
102- TURTLE : 'turtle' ,
103- N3 : 'n3' ,
104- MVT : 'mvt' ,
105- } as const ;
106-
107- export type ExportDatasetFormat =
108- typeof EnumExportDatasetFormat [ keyof typeof EnumExportDatasetFormat ] ;
82+
83+ export type ExportCatalogFormat = ValueOf < typeof EXPORT_CATALOG_FORMAT > ;
84+
85+ export type ExportDatasetFormat = ValueOf < typeof EXPORT_DATASET_FORMAT > ;
0 commit comments