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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
use crate::types::consts::{buffer_out_param, buffer_out_size_param};
use crate::types::consts::{INTERNAL_ERROR_IDENT, INVALID_PARAM_IDENT};
use crate::types::structs::*;
use indoc::indoc;
pub fn project_type() -> Type {
const PROJECT_PARAM_NAME: &'static str = "project";
const PROJECT_PARAM_TYPE: &'static str = "Project";
let project_param = |desc| -> Parameter {
Parameter {
name: PROJECT_PARAM_NAME,
r#type: PROJECT_PARAM_TYPE,
description: desc,
log_level: LogLevel::Info,
validations: vec![ParameterValidation {
r#type: ParameterValidationType::NotNull,
flag_condition: None,
}],
}
};
Type {
name: "project",
description: indoc! {r#"
A project represents a persistent workspace of Ikarus-related data.
Each project can contain any number of entities.
"#},
functions: vec![
Function {
name: "open",
description: "Opens a project at a specific path in the filesystem.",
log_level: LogLevel::Info,
db_access: DbAccess::NoAccess,
versions: vec![
FunctionVersion {
description: None,
log_level: None,
db_access: None,
flags: vec![
Flag {
name: "MustExist",
description: indoc! {r#"
Overrides the default behaviour, causing a non-existent project to cause an error instead of the creation of one.
"#},
},
Flag {
name: "CreateParents",
description: "If specified a path to a non-existent directory will have all its parent-directories created.",
},
],
parameters: vec![
Parameter {
name: "path",
description: indoc! {r#"
The path on the filesystem where you want to store the project.
The path must point to a valid filename within an existing directory.
If no project exist at the specified path, one is created.
"#},
r#type: "String",
log_level: LogLevel::Info,
validations: vec![
ParameterValidation {
r#type: ParameterValidationType::NotNull,
flag_condition: None,
},
ParameterValidation {
r#type: ParameterValidationType::ValidUtf8,
flag_condition: None,
},
ParameterValidation {
r#type: ParameterValidationType::PathExists,
flag_condition: Some(FlagCondition {
inverted: false,
flag: "MustExist",
}),
},
ParameterValidation {
r#type: ParameterValidationType::PathParentMustExist,
flag_condition: Some(FlagCondition {
inverted: true,
flag: "CreateParents",
}),
},
],
}
],
r#return: Some(ReturnType {
name: PROJECT_PARAM_NAME,
r#type: PROJECT_PARAM_TYPE,
description: indoc! {r#"
An opaque handle to the project or an undefined handle if an error occurred.
A valid pointer must be freed using either `close_project` or `delete_project`.
"#},
}),
errors: vec![
Error {
r#type: INTERNAL_ERROR_IDENT,
occurrences: vec![
"When we fail to initialise the project.",
"When we fail to open the project.",
"When we fail to migrate the project.",
],
},
Error {
r#type: INVALID_PARAM_IDENT,
occurrences: vec![
"When you try to open a project with a future version."
],
}
],
}
],
},
Function {
name: "close",
description: indoc!{r#"
Closes a project previously opened with `open_project`.
On success, all data is saved and persisted and the pointer is freed and must not be used afterwards.
Any error occurring will leave the pointer intact.
Error's occurring in this function should be met with a retry mechanism.
"#},
log_level: LogLevel::Info,
db_access: DbAccess::ReadWrite,
versions: vec![
FunctionVersion {
description: None,
log_level: None,
db_access: None,
flags: vec![],
parameters: vec![
project_param("The project you want to close.")
],
r#return: None,
errors: vec![
Error{
r#type: INTERNAL_ERROR_IDENT,
occurrences: vec![
"When we fail to close the project."
],
}
],
}
],
},
Function {
name: "delete",
description: indoc!{r#"
Closes & deletes a project from the underlying filesystem.
On success, all data is erased. The handle is freed and must not be used afterwards.
Any error occurring will leave the handle intact.
"#},
log_level: LogLevel::Info,
db_access: DbAccess::ReadWrite,
versions: vec![
FunctionVersion {
description: None,
log_level: None,
db_access: None,
flags: vec![],
parameters: vec![
Parameter{
name: "project",
r#type: "Project",
description: "The project you want to delete.",
log_level: LogLevel::Info,
validations: vec![
ParameterValidation {
r#type: ParameterValidationType::NotNull,
flag_condition: None,
}
],
}
],
r#return: None,
errors: vec![
Error {
r#type: INTERNAL_ERROR_IDENT,
occurrences: vec![
"When we are unable to close the project before deletion.",
"When we are unable to delete the file from the filesystem."
],
}
],
}
],
},
Function {
name: "get_entities",
description: indoc!{r#"
Fetches a number of entities within a project in an unspecified order.
Should be used in conjunction with `get_entities_count` to fetch all entities at once."
"#},
log_level: LogLevel::Verbose,
db_access: DbAccess::ReadOnly,
versions: vec![
FunctionVersion {
description: None,
log_level: None,
db_access: None,
flags: vec![],
parameters: vec![
project_param("The project whose entities you want to fetch."),
buffer_out_param("entities", "*mut Id", "The pre-allocated buffer in which we will store the entities."),
buffer_out_size_param("entities_out_size", "usize", "The size of the entities_out buffer."),
Parameter {
name: "entity_types",
r#type: "EntityTypes",
description: "The types of entities you want to fetch.",
log_level: LogLevel::Verbose,
validations: vec![],
}
],
r#return: None,
errors: vec![
Error {
r#type: INTERNAL_ERROR_IDENT,
occurrences: vec![
"When we experience an error accessing the project."
],
}
],
}
],
},
Function {
name: "get_entities_count",
description: indoc!{r#"
Fetches the count of entities present in a project.
Can be used to figure out the ideal size of the buffer for `get_entities`.
"#},
log_level: LogLevel::Verbose,
db_access: DbAccess::ReadOnly,
versions: vec![
FunctionVersion {
description: None,
log_level: None,
db_access: None,
flags: vec![],
parameters: vec![
project_param("The project whose entity count you want to fetch."),
Parameter {
name: "entity_types",
r#type: "EntityTypes",
description: "The types of entities you want to fetch.",
log_level: LogLevel::Verbose,
validations: vec![],
}
],
r#return: Some(
ReturnType {
name: "count",
r#type: "usize",
description: "The amount of entities present in the project with the given parameters."
}
),
errors: vec![
Error {
r#type: INTERNAL_ERROR_IDENT,
occurrences: vec![
"When we experience an error accessing the project."
],
}
],
}
],
}
],
}
}