Skip to content

Commit 0ce87e0

Browse files
* feat(types): update and new types (#259)
- Dataset has no longer optional keys and new keys has been added such as `alternative_exports` - Dataset field types have been defined - Enrich request data types with the _links key (If request contains the include_links params) - Expose proper constants for export types
1 parent b9987af commit 0ce87e0

File tree

5 files changed

+95
-69
lines changed

5 files changed

+95
-69
lines changed
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
export const ODS_DATASET_FIELD_TYPE = {
2+
TEXT: 'text',
3+
INT: 'int',
4+
DOUBLE: 'double',
5+
BOOLEAN: 'boolean',
6+
GEO_SHAPE: 'geo_shape',
7+
GEO_POINT_2D: 'geo_point_2d',
8+
DATETIME: 'datetime',
9+
DATE: 'date',
10+
IMAGE: 'image',
11+
FILE: 'file',
12+
JSON: 'json',
13+
} as const;
14+
15+
export const EXPORT_DATASET_FORMAT = {
16+
JSON: 'json',
17+
GEOJSON: 'geojson',
18+
SHP: 'shp',
19+
CSV: 'csv',
20+
XLSX: 'xlsx',
21+
KML: 'kml',
22+
JSONLD: 'jsonld',
23+
JSONL: 'jsonl',
24+
RDFXML: 'rdfxml',
25+
TURTLE: 'turtle',
26+
N3: 'n3',
27+
MVT: 'mvt',
28+
} as const;
29+
30+
export const EXPORT_CATALOG_FORMAT = {
31+
CSV: 'csv',
32+
JSON: 'json',
33+
XLSX: 'xlsx',
34+
RDF: 'rdf',
35+
TTL: 'ttl',
36+
DATA_JSON: 'data.json',
37+
RSS: 'rss',
38+
DCAT: 'dcat',
39+
DCAT_AP_CH: 'dcat-ap-ch',
40+
DCAT_AP_IT: 'dcat-ap-it',
41+
DCAT_AP_DE: 'dcat-ap-de',
42+
DCAT_AP_SE: 'dcat-ap-se',
43+
DCAT_AP_SP: 'dcat-ap-sp',
44+
DCAT_AP_V1: 'dcat-ap-v1',
45+
DCAT_AP_BENAP: 'dcat_ap_benap',
46+
} as const;
Lines changed: 46 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
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+
36
export 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+
5864
export 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

6879
export 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>;

packages/api-client/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,6 @@
66
export * from './client';
77
export * from './client/error';
88
export * from './client/types';
9+
export * from './client/constants';
910
export * from './odsql';
1011
export * from './odsql/clauses';
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './typescript';
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export type ValueOf<V> = V[keyof V];

0 commit comments

Comments
 (0)