-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathPlaceProperties.ts
More file actions
258 lines (235 loc) · 6.39 KB
/
Copy pathPlaceProperties.ts
File metadata and controls
258 lines (235 loc) · 6.39 KB
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
import { SchemaDefinition, ValidationError } from '@sozialhelden/simpl-schema';
import { Accessibility, getAccessibilitySchemaDefinition } from './Accessibility.js';
import { StructuredAddress, getStructuredAddressSchemaDefinition } from './Address.js';
import { getLocalizedStringSchemaDefinition, LocalizedString } from './LocalizedString.js';
import getPrefixedSchemaDefinition from './lib/getPrefixedSchemaDefinition.js';
import { AccessType, AccessTypes } from './AccessType.js';
import validateEmail from './validateEmail.js';
import validateUrl from './validateUrl.js';
/**
* Properties of a place of interest.
*/
export interface PlaceProperties {
/**
* The official name of this place.
*/
name?: LocalizedString;
/**
* The address of this place. `null` indicates that this place has no address, `undefined` or
* missing property indicates unknown.
*/
address?: StructuredAddress | null;
/**
* Text description containing helpful information for people with disabilities.
*/
description?: LocalizedString;
/**
* Phone number to call a representant of the place's operator.
*/
phoneNumber?: string;
/**
* Email address of the place's operator where you can get accessibility relevant information.
*/
emailAddress?: string;
/**
* Category name of the place
* @example ‘restaurant’
*/
category: string;
/**
* The accessibility of this place. `null` indicates that this place has no data, `undefined` or
* missing property indicates unknown.
*/
accessibility?: Accessibility | null;
// - machine data fields -
/**
* ID of the parent place that this place belongs to.
*/
parentPlaceInfoId?: string;
/**
* The parent's place ID in the original dataset from the data provider.
*/
originalParentPlaceInfoId?: string;
/**
* Source ID of the parent place that this place belongs to. This is usually the same ID as
* `sourceId`, but the parent place can be from another data provider.
*/
parentPlaceSourceId?: string;
/**
* ID of the data source that provided the place (accessibility.cloud ID)
*/
sourceId?: string;
/**
* ID of the import that created this place (accessibility.cloud ID)
*/
sourceImportId?: string;
/**
* ID of this place of interest in the original data source. To simplify communication with the
* data provider, it’s a good idea to use the provider's internal ID here.
*/
originalId?: string;
/**
* URLs of this equipment in external data sources, for example in GTFS, IMDF or other sources.
*/
sameAs?: string[];
/**
* Original source data for this equipment (for easier debugging)
*/
originalData?: any;
/**
* IDs in other data sources that are linked to this equipment, indexed by schema/context.
*/
ids?: Record<string, string>;
/**
* URL of the original data source’s website describing this place.
*/
infoPageUrl?: string;
/**
* URL of the original data source’s website on a subpage that allows to edit the original data.
*/
editPageUrl?: string;
/**
* URL of the place’s own website.
*/
placeWebsiteUrl?: string;
/**
* Defines who this restroom is for. See https://wiki.openstreetmap.org/wiki/Key:access for more
* information.
*/
access?: AccessType[];
/**
* Tags that are not part of the schema, but are still useful for the data consumer.
*
* - If a OSM place is described, the tags are the OSM tags.
* - If a GTFS place is described, the tags are the GTFS fields.
* - If a IMDF place is described, the tags are the IMDF fields.
* - If a custom place is described, the tags are the custom fields.
* - If a place is described by a combination of multiple sources, the tags are the union of all
* fields.
*
* @example { 'healthcare': 'dentist' }
*/
tags?: Record<string, string>;
}
export const getPlacePropertiesSchemaDefinition: () => SchemaDefinition = () => ({
...getLocalizedStringSchemaDefinition('name'),
category: {
type: String,
},
...getPrefixedSchemaDefinition('address', getStructuredAddressSchemaDefinition()),
...getLocalizedStringSchemaDefinition('description'),
phoneNumber: {
type: String,
optional: true,
},
emailAddress: {
type: String,
custom: validateEmail,
optional: true,
},
...getPrefixedSchemaDefinition('accessibility', getAccessibilitySchemaDefinition()),
infoPageUrl: {
type: String,
custom: validateUrl,
optional: true,
},
editPageUrl: {
type: String,
custom: validateUrl,
optional: true,
},
placeWebsiteUrl: {
type: String,
custom: validateUrl,
optional: true,
},
// machine data fields
sameAs: {
type: Array,
optional: true,
},
'sameAs.$': {
type: String,
},
ids: {
type: Object,
optional: true,
blackbox: true,
},
originalId: {
type: String,
optional: true,
},
parentPlaceInfoId: {
type: String,
optional: true,
},
originalParentPlaceInfoId: {
type: String,
optional: true,
},
parentPlaceSourceId: {
type: String,
optional: true,
},
originalData: {
type: String,
optional: true,
},
sourceId: {
type: String,
optional: true,
},
sourceImportId: {
type: String,
optional: true,
},
access: {
type: Array,
optional: true,
},
'access.$': {
type: String,
allowedValues: (AccessTypes as any) as any[],
},
tags: {
type: Object,
optional: true,
blackbox: true,
custom(): string | undefined {
if (!this.isSet) {
return undefined;
}
const { value } = this;
if (typeof value !== 'object' || value instanceof Array || typeof value === 'string' || value === null || value === undefined) {
return 'expectedType';
}
const keys = Object.keys(value);
if (keys.length === 0) {
return 'mustHaveAtLeastOneKey';
}
const errors: ValidationError[] = [];
keys.forEach((key) => {
const interactionMode = value[key];
if (
typeof interactionMode !== 'string'
) {
errors.push({
name: `interactions.${key}`,
type: 'expectedType',
value: interactionMode,
});
}
if (errors.length > 0) {
this.addValidationErrors(errors);
return false;
}
return undefined;
});
return undefined;
},
},
'tags.$': {
type: String,
},
});