-
Notifications
You must be signed in to change notification settings - Fork 1
/
system.go
396 lines (340 loc) · 10.5 KB
/
system.go
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
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
package directus
import (
"encoding/json"
"github.com/perimeterx/marshmallow"
)
type Collection struct {
Collection string `json:"collection"`
Meta CollectionMeta `json:"meta"`
Schema *CollectionSchema `json:"schema,omitempty"`
Fields []*Field `json:"fields,omitempty"`
}
type CollectionMeta struct {
Collection string `json:"collection,omitempty"`
Color string `json:"color,omitempty"`
Icon Icon `json:"icon,omitempty"`
Note string `json:"note,omitempty"`
Hidden bool `json:"hidden"`
Singleton bool `json:"singleton"`
ArchiveField string `json:"archive_field,omitempty"`
ArchiveValue string `json:"archive_value,omitempty"`
UnarchiveValue string `json:"unarchive_value,omitempty"`
ArchiveAppFilter bool `json:"archive_app_filter"`
SortField string `json:"sort_field,omitempty"`
Group Nullable[string] `json:"group,omitempty"`
Sort int64 `json:"sort,omitempty"`
Collapse CollectionCollapse `json:"collapse,omitempty"`
Versioning bool `json:"versioning,omitempty"`
Accountability Nullable[Accountability] `json:"accountability"`
System bool `json:"system,omitempty"`
PreviewURL string `json:"preview_url,omitempty"`
DisplayTemplate string `json:"display_template,omitempty"`
Translations []*CollectionTranslation `json:"translations,omitempty"`
Unknown map[string]any `json:"-"`
}
func (meta *CollectionMeta) UnmarshalJSON(data []byte) error {
values, err := marshmallow.Unmarshal(data, meta, marshmallow.WithExcludeKnownFieldsFromMap(true))
if err != nil {
return err
}
meta.Unknown = values
return nil
}
func (meta *CollectionMeta) MarshalJSON() ([]byte, error) {
type alias CollectionMeta
base, err := json.Marshal((*alias)(meta))
if err != nil {
return nil, err
}
m := make(map[string]any)
for k, v := range meta.Unknown {
m[k] = v
}
if err := json.Unmarshal(base, &m); err != nil {
return nil, err
}
return json.Marshal(m)
}
func (meta *CollectionMeta) Translation(language string) *CollectionTranslation {
for _, t := range meta.Translations {
if t.Language == language {
return t
}
}
return nil
}
type CollectionCollapse string
const (
CollectionCollapseOpen CollectionCollapse = "open"
CollectionCollapseClosed CollectionCollapse = "closed"
CollectionCollapseLocked CollectionCollapse = "locked"
)
func (collapse *CollectionCollapse) UnmarshalJSON(data []byte) error {
var str string
if err := json.Unmarshal(data, &str); err != nil {
return err
}
*collapse = CollectionCollapse(str)
return nil
}
func (collapse *CollectionCollapse) MarshalJSON() ([]byte, error) {
return json.Marshal(string(*collapse))
}
type CollectionTranslation struct {
Language string `json:"language"`
Singular string `json:"singular"`
Plural string `json:"plural"`
Translation string `json:"translation"`
}
type CollectionSchema struct {
Name string `json:"name"`
Comment string `json:"comment,omitempty"`
Collation string `json:"collation,omitempty"`
Engine string `json:"engine,omitempty"`
Schema string `json:"schema,omitempty"`
Unknown map[string]any `json:"-"`
}
func (schema *CollectionSchema) UnmarshalJSON(data []byte) error {
values, err := marshmallow.Unmarshal(data, schema, marshmallow.WithExcludeKnownFieldsFromMap(true))
if err != nil {
return err
}
schema.Unknown = values
return nil
}
func (schema *CollectionSchema) MarshalJSON() ([]byte, error) {
type alias CollectionSchema
base, err := json.Marshal((*alias)(schema))
if err != nil {
return nil, err
}
m := make(map[string]any)
for k, v := range schema.Unknown {
m[k] = v
}
if err := json.Unmarshal(base, &m); err != nil {
return nil, err
}
return json.Marshal(m)
}
type Accountability string
const (
AccountabilityAll Accountability = "all"
AccountabilityActivity Accountability = "activity"
)
func (accountability *Accountability) UnmarshalJSON(data []byte) error {
var str string
if err := json.Unmarshal(data, &str); err != nil {
return err
}
*accountability = Accountability(str)
return nil
}
func (accountability *Accountability) MarshalJSON() ([]byte, error) {
return json.Marshal(string(*accountability))
}
type CustomTranslation struct {
ID string `json:"id,omitempty"`
Key string `json:"key,omitempty"`
Language string `json:"language,omitempty"`
Value string `json:"value"`
}
type Folder struct {
ID string `json:"id,omitempty"`
Name string `json:"name"`
Parent Nullable[string] `json:"parent"`
}
type Preset struct {
ID int64 `json:"id,omitempty"`
Bookmark Nullable[string] `json:"bookmark"`
User Nullable[string] `json:"user"`
Role Nullable[string] `json:"role"`
Collection string `json:"collection"`
Layout Nullable[string] `json:"layout"`
Icon Nullable[string] `json:"icon"`
Unknown map[string]any `json:"-"`
}
func (preset *Preset) UnmarshalJSON(data []byte) error {
values, err := marshmallow.Unmarshal(data, preset, marshmallow.WithExcludeKnownFieldsFromMap(true))
if err != nil {
return err
}
preset.Unknown = values
return nil
}
func (preset *Preset) MarshalJSON() ([]byte, error) {
type alias Preset
base, err := json.Marshal((*alias)(preset))
if err != nil {
return nil, err
}
m := make(map[string]any)
for k, v := range preset.Unknown {
m[k] = v
}
if err := json.Unmarshal(base, &m); err != nil {
return nil, err
}
return json.Marshal(m)
}
type Operation struct {
ID string `json:"id,omitempty"`
Flow string `json:"flow"`
Key string `json:"key"`
PositionX int32 `json:"position_x"`
PositionY int32 `json:"position_y"`
Type string `json:"type"`
Name Nullable[string] `json:"name"`
Reject Nullable[string] `json:"reject"`
Resolve Nullable[string] `json:"resolve"`
UserCreated Nullable[string] `json:"user_created"`
Unknown map[string]any `json:"-"`
}
func (operation *Operation) UnmarshalJSON(data []byte) error {
values, err := marshmallow.Unmarshal(data, operation, marshmallow.WithExcludeKnownFieldsFromMap(true))
if err != nil {
return err
}
operation.Unknown = values
return nil
}
func (operation *Operation) MarshalJSON() ([]byte, error) {
type alias Operation
base, err := json.Marshal((*alias)(operation))
if err != nil {
return nil, err
}
m := make(map[string]any)
for k, v := range operation.Unknown {
m[k] = v
}
if err := json.Unmarshal(base, &m); err != nil {
return nil, err
}
return json.Marshal(m)
}
type Flow struct {
ID string `json:"id,omitempty"`
Name string `json:"name"`
Status string `json:"status"`
Description Nullable[string] `json:"description"`
Accountability Accountability `json:"accountability"`
Color string `json:"color,omitempty"`
Icon Icon `json:"icon,omitempty"`
Operation Nullable[string] `json:"operation"`
Operations []string `json:"operations,omitempty"`
UserCreated Nullable[string] `json:"user_created"`
Unknown map[string]any `json:"-"`
}
func (flow *Flow) UnmarshalJSON(data []byte) error {
values, err := marshmallow.Unmarshal(data, flow, marshmallow.WithExcludeKnownFieldsFromMap(true))
if err != nil {
return err
}
flow.Unknown = values
return nil
}
func (flow *Flow) MarshalJSON() ([]byte, error) {
type alias Flow
base, err := json.Marshal((*alias)(flow))
if err != nil {
return nil, err
}
m := make(map[string]any)
for k, v := range flow.Unknown {
m[k] = v
}
if err := json.Unmarshal(base, &m); err != nil {
return nil, err
}
return json.Marshal(m)
}
type File struct {
FileSize Nullable[int64] `json:"file_size"`
ID string `json:"id,omitempty"`
Folder Nullable[string] `json:"folder"`
Title Nullable[string] `json:"title"`
Type Nullable[string] `json:"type"`
Description Nullable[string] `json:"description"`
Storage string `json:"storage"`
Charset Nullable[string] `json:"charset"`
FilenameDowload string `json:"filename_download"`
FocalPointX Nullable[int32] `json:"focal_point_x"`
FocalPointY Nullable[int32] `json:"focal_point_y"`
Width Nullable[int32] `json:"width"`
Height Nullable[int32] `json:"height"`
Duration Nullable[int32] `json:"duration"`
Location Nullable[string] `json:"location"`
Tags Nullable[string] `json:"tags"`
Embed Nullable[string] `json:"embed"`
FilenameDisk Nullable[string] `json:"filename_disk"`
Unknown map[string]any `json:"-"`
}
func (file *File) UnmarshalJSON(data []byte) error {
values, err := marshmallow.Unmarshal(data, file, marshmallow.WithExcludeKnownFieldsFromMap(true))
if err != nil {
return err
}
file.Unknown = values
return nil
}
func (file *File) MarshalJSON() ([]byte, error) {
type alias File
base, err := json.Marshal((*alias)(file))
if err != nil {
return nil, err
}
m := make(map[string]any)
for k, v := range file.Unknown {
m[k] = v
}
if err := json.Unmarshal(base, &m); err != nil {
return nil, err
}
return json.Marshal(m)
}
type Dashboard struct {
ID string `json:"id,omitempty"`
Name string `json:"name"`
Icon Icon `json:"icon"`
Color Nullable[string] `json:"color"`
Note Nullable[string] `json:"note"`
}
type Panel struct {
ID string `json:"id,omitempty"`
Dashboard string `json:"dashboard"`
Height int32 `json:"height"`
Width int32 `json:"width"`
PositionX int32 `json:"position_x"`
PositionY int32 `json:"position_y"`
ShowHeader bool `json:"show_header"`
Type string `json:"type"`
Color Nullable[string] `json:"color"`
Icon Icon `json:"icon"`
Name Nullable[string] `json:"name"`
Note Nullable[string] `json:"note"`
Unknown map[string]any `json:"-"`
}
func (panel *Panel) UnmarshalJSON(data []byte) error {
values, err := marshmallow.Unmarshal(data, panel, marshmallow.WithExcludeKnownFieldsFromMap(true))
if err != nil {
return err
}
panel.Unknown = values
return nil
}
func (panel *Panel) MarshalJSON() ([]byte, error) {
type alias Panel
base, err := json.Marshal((*alias)(panel))
if err != nil {
return nil, err
}
m := make(map[string]any)
for k, v := range panel.Unknown {
m[k] = v
}
if err := json.Unmarshal(base, &m); err != nil {
return nil, err
}
return json.Marshal(m)
}