Skip to content

Commit

Permalink
feat(types): update and add new dataset types
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinFabre-ods committed Aug 30, 2024
1 parent b9987af commit 748423f
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 49 deletions.
45 changes: 45 additions & 0 deletions packages/api-client/src/client/constants.ts
Original file line number Diff line number Diff line change
@@ -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;
89 changes: 40 additions & 49 deletions packages/api-client/src/client/types.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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<string, any>;
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<string, any>;
fields: OdsDatasetField[];
visibility: 'restricted' | 'domain';
attachements: OdsDatasetAttachement[]
alternative_exports: OdsDatasetAlternativeExport[]
}

export interface OdsRecord<T> {
Expand Down Expand Up @@ -68,41 +88,12 @@ export interface ApiQuery<T> {
export interface ApiExport<T> {
[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];
1 change: 1 addition & 0 deletions packages/api-client/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

0 comments on commit 748423f

Please sign in to comment.