-
Notifications
You must be signed in to change notification settings - Fork 1
/
schemas.js
284 lines (256 loc) · 7.74 KB
/
schemas.js
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
/**
* This module provides code a set of schemas for params passed to
* the nunjuck templates in `./src/views`
*/
import * as v from 'valibot'
export const EmptyParams = v.object({})
export const UptimeParams = v.object({
upTime: v.string()
})
export const ErrorParams = v.strictObject({
err: v.object({})
})
export const NonEmptyString = v.pipe(v.string(), v.nonEmpty())
export const Base = v.object({
// serviceName: NonEmptyString,
// pageTitle: NonEmptyString,
pageName: v.optional(NonEmptyString)
})
export const StartPage = v.object({
...Base.entries
})
export const PaginationParams = v.optional(v.strictObject({
previous: v.optional(v.strictObject({
href: v.string()
})),
next: v.optional(v.strictObject({
href: v.string()
})),
items: v.array(v.variant('type', [
v.strictObject({
type: v.literal('number'),
number: v.integer(),
href: v.string(),
current: v.boolean()
}),
v.strictObject({
type: v.literal('ellipsis'),
ellipsis: v.literal(true),
href: v.string()
})
]))
}))
export const tableParams = v.strictObject({
columns: v.array(NonEmptyString),
rows: v.array(v.strictObject({
columns: v.objectWithRest(
{},
v.strictObject({
error: v.optional(v.object({
message: v.string()
})),
value: v.optional(v.string()),
html: v.optional(v.string()),
classes: v.optional(v.string())
})
)
})),
fields: v.array(NonEmptyString)
})
/**
* The values of this enum should match values of the 'status' column
* in the query in `fetchLpaOverview` middleware
*/
export const datasetStatusEnum = {
Live: 'Live',
'Needs fixing': 'Needs fixing',
Warning: 'Warning',
Error: 'Error',
'Not submitted': 'Not submitted'
}
const OrgField = v.strictObject({ name: NonEmptyString, organisation: NonEmptyString, statistical_geography: v.optional(v.string()), entity: v.optional(v.integer()) })
const DatasetNameField = v.strictObject({ name: NonEmptyString, dataset: NonEmptyString, collection: NonEmptyString })
export const OrgOverviewPage = v.strictObject({
organisation: OrgField,
datasets: v.array(v.strictObject({
endpoint: v.optional(v.url()),
status: v.enum(datasetStatusEnum),
slug: NonEmptyString,
issue_count: v.optional(v.number()),
error: v.optional(v.nullable(NonEmptyString)),
http_error: v.optional(NonEmptyString),
issue: v.optional(NonEmptyString),
entity_count: v.optional(v.number()),
// synthetic entry, represents a user friendly count (e.g. count missing value in a column as 1 issue)
numIssues: v.optional(v.number())
})),
totalDatasets: v.integer(),
datasetsWithEndpoints: v.integer(),
datasetsWithIssues: v.integer(),
datasetsWithErrors: v.integer()
})
export const OrgFindPage = v.strictObject({
alphabetisedOrgs: v.record(NonEmptyString, v.array(OrgField))
})
export const OrgGetStarted = v.strictObject({
organisation: OrgField,
dataset: DatasetNameField
})
export const OrgDatasetOverview = v.strictObject({
organisation: OrgField,
dataset: DatasetNameField,
taskCount: v.integer(),
stats: v.strictObject({
numberOfRecords: v.integer(),
numberOfFieldsSupplied: v.integer(),
numberOfFieldsMatched: v.integer(),
numberOfExpectedFields: v.integer(),
endpoints: v.array(v.strictObject({
name: v.string(),
documentation_url: v.optional(v.string()),
endpoint: v.string(),
lastAccessed: v.string(),
lastUpdated: v.string(),
error: v.optional(v.strictObject({
code: v.integer(),
exception: v.string()
}))
}))
})
})
export const OrgDataView = v.strictObject({
organisation: OrgField,
dataset: DatasetNameField,
taskCount: v.integer(),
tableParams,
pagination: PaginationParams,
dataRange: v.strictObject({
minRow: v.integer(),
maxRow: v.integer(),
totalRows: v.integer()
})
})
export const OrgDatasetTaskList = v.strictObject({
taskList: v.array(v.strictObject({
title: v.strictObject({ text: NonEmptyString }),
href: v.url(),
status: v.strictObject({
tag: v.strictObject({
classes: NonEmptyString,
text: NonEmptyString
})
})
})),
organisation: OrgField,
dataset: v.strictObject({
dataset: v.optional(NonEmptyString),
name: NonEmptyString,
collection: NonEmptyString
})
})
export const OrgEndpointError = v.strictObject({
organisation: OrgField,
dataset: DatasetNameField,
errorData: v.strictObject({
endpoint_url: v.url(),
http_status: v.integer(),
latest_log_entry_date: v.isoDateTime(),
latest_200_date: v.isoDateTime()
})
})
export const OrgIssueDetails = v.strictObject({
organisation: OrgField,
dataset: DatasetNameField,
errorHeading: v.optional(NonEmptyString),
issueItems: v.array(v.strictObject({
html: v.string(),
href: v.url()
})),
issueType: NonEmptyString,
entry: v.strictObject({
title: NonEmptyString,
fields: v.array(v.strictObject({
key: v.strictObject({ text: NonEmptyString }),
value: v.strictObject({ html: v.string() }),
classes: v.string()
})),
geometries: v.optional(v.array(v.string()))
}),
pagination: PaginationParams,
issueEntitiesCount: v.integer(),
pageNumber: v.integer()
})
export const CheckAnswers = v.strictObject({
values: v.strictObject({
lpa: NonEmptyString,
name: NonEmptyString,
email: v.pipe(v.string(), v.email()),
dataset: NonEmptyString,
'endpoint-url': v.url(),
'documentation-url': v.url(),
hasLicence: NonEmptyString
})
})
export const ChooseDataset = v.strictObject({
errors: v.strictObject({
dataset: v.optional(v.strictObject({
type: v.enum({
required: 'required'
})
}))
})
})
export const DatasetDetails = v.strictObject({
organisation: OrgField,
dataset: DatasetNameField,
values: v.strictObject({
dataset: NonEmptyString
}),
errors: v.record(NonEmptyString, v.strictObject({
type: NonEmptyString
}))
})
export const GuidanceNavigationItem = v.strictObject({
label: NonEmptyString,
url: v.string(),
items: v.optional(v.lazy(() => v.array(GuidanceNavigationItem)))
})
export const GuidanceNavigation = v.strictObject({
navigation: v.array(v.strictObject({
title: NonEmptyString,
items: v.array(GuidanceNavigationItem)
}))
})
/**
* This acts as a registry of template -> schema for convenience.
*/
export const templateSchema = new Map([
['dataset-details.html', DatasetDetails],
['check-answers.html', CheckAnswers],
['choose-dataset.html', ChooseDataset],
['lpa-details.html', v.any()],
['submit/confirmation.html', v.any()],
['organisations/overview.html', OrgOverviewPage],
['organisations/find.html', OrgFindPage],
['organisations/get-started.html', OrgGetStarted],
['organisations/dataset-overview.html', OrgDatasetOverview],
['organisations/dataview.html', OrgDataView],
['organisations/datasetTaskList.html', OrgDatasetTaskList],
['organisations/http-error.html', OrgEndpointError],
['organisations/issueDetails.html', OrgIssueDetails],
['errorPages/503', UptimeParams],
['errorPages/500', ErrorParams],
['errorPages/404', EmptyParams],
['privacy-notice.html', EmptyParams],
['landing.html', EmptyParams],
['cookies.html', EmptyParams],
['accessibility.html', EmptyParams],
['guidance/index.md', GuidanceNavigation],
['guidance/try-check-publish-service', GuidanceNavigation],
['guidance/publish-data-on-your-website', GuidanceNavigation],
['guidance/keep-your-data-up-to-date', GuidanceNavigation],
['guidance/specifications/index.md', GuidanceNavigation],
['guidance/specifications/article-4-direction', GuidanceNavigation],
['guidance/specifications/conservation-area', GuidanceNavigation],
['guidance/specifications/listed-building', GuidanceNavigation]
])