jupyter_serde/media/
datatable.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
use serde::{Deserialize, Serialize};
use std::collections::HashMap;

/// See https://specs.frictionlessdata.io/tabular-data-resource/
#[derive(Default, Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub struct TabularDataResource {
    pub path: Option<PathOrPaths>,
    pub data: Option<Vec<serde_json::Value>>,
    pub schema: TableSchema,

    pub title: Option<String>,
    pub description: Option<String>,
    pub homepage: Option<String>,
    pub sources: Option<Vec<Source>>,
    pub licenses: Option<Vec<License>>,
    pub dialect: Option<Dialect>,
    pub format: Option<String>,
    pub mediatype: Option<String>,
    pub encoding: Option<String>,
    pub bytes: Option<i64>,
    pub hash: Option<String>,
}

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
#[serde(untagged)]
pub enum PathOrPaths {
    Single(String),
    Multiple(Vec<String>),
}

#[derive(Default, Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub struct TableSchema {
    pub fields: Vec<TableSchemaField>,
    pub primary_key: Option<PrimaryKey>,
    pub foreign_keys: Option<Vec<ForeignKey>>,
    pub missing_values: Option<Vec<String>>,
}

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
#[serde(rename_all = "camelCase", untagged)]
pub enum PrimaryKey {
    Single(String),
    Multiple(Vec<String>),
}

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub struct ForeignKey {
    pub fields: ForeignKeyFields,
    pub reference: ForeignKeyReference,
}

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
#[serde(untagged)]
pub enum ForeignKeyFields {
    Single(String),
    Multiple(Vec<String>),
}

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub struct ForeignKeyReference {
    pub resource: String,
    pub fields: ForeignKeyFields,
}

#[derive(Default, Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub struct TableSchemaField {
    pub name: String,
    pub title: Option<String>,
    pub description: Option<String>,
    pub example: Option<String>,
    #[serde(rename = "type")]
    pub field_type: FieldType,
    pub format: Option<FieldFormat>,
    pub constraints: Option<HashMap<String, serde_json::Value>>,
    pub rdf_type: Option<String>,
}

#[derive(Default, Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
#[serde(rename_all = "lowercase")]
pub enum FieldType {
    String,
    Number,
    Integer,
    Date,
    Time,
    Datetime,
    Year,
    Yearmonth,
    Boolean,
    Object,
    Geopoint,
    Geojson,
    Array,
    Duration,
    #[default]
    Any,
}

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
#[serde(rename_all = "lowercase")]
pub enum FieldFormat {
    Default,
    Email,
    Uri,
    Binary,
    Uuid,
    Any,
    Array,
    Object,
}

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub struct Source {
    pub title: String,
    pub path: Option<String>,
    pub email: Option<String>,
}

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub struct License {
    pub name: Option<String>,
    pub path: Option<String>,
    pub title: Option<String>,
}

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub struct Dialect {
    pub delimiter: Option<String>,
    pub double_quote: Option<bool>,
    pub line_terminator: Option<String>,
    pub null_sequence: Option<String>,
    pub quote_char: Option<String>,
    pub escape_char: Option<String>,
    pub skip_initial_space: Option<bool>,
    pub header: Option<bool>,
    pub comment_char: Option<String>,
    pub case_sensitive_header: Option<bool>,
}