mapeo-schema
Version:
JSON schema and flow types for Mapeo
213 lines (192 loc) • 4.61 kB
Flow
// @flow
export type Common = {
id: string,
version: string,
created_at: string,
timestamp?: string,
userId?: string,
deviceId?: string,
type: string,
links?: Array<string>,
schemaVersion?: number,
};
export type Field = {|
id: string,
key: string | Array<string>,
type: "text" | "localized" | "number" | "select_one" | "select_multiple" | "date" | "datetime",
label?: string,
readonly?: boolean,
appearance?: "singleline" | "multiline",
snake_case?: boolean,
options?: Array<(string | boolean | number | null | {
label?: string,
value: string | boolean | number | null,
})>,
universal?: boolean,
placeholder?: string,
helperText?: string,
min_value?: number,
max_value?: number,
|};
export type Filter = {
id: string,
version: string,
created_at: string,
timestamp?: string,
userId?: string,
deviceId?: string,
type: "filter",
links?: Array<string>,
schemaVersion: 1,
filter: any,
name: string,
};
export type Position = {
timestamp?: number,
mocked?: boolean,
coords?: {
altitude?: number,
heading?: number,
longitude?: number,
speed?: number,
latitude?: number,
accuracy?: number,
},
};
export type Observation = {
id: string,
version: string,
created_at: string,
timestamp?: string,
userId?: string,
deviceId?: string,
type: "observation",
links?: Array<string>,
schemaVersion: 4,
lat?: number | null,
lon?: number | null,
metadata?: {
position?: Position,
lastSavedPosition?: Position,
positionProvider?: {
gpsAvailable?: boolean,
passiveAvailable?: boolean,
locationServicesEnabled?: boolean,
networkAvailable?: boolean,
},
manualLocation?: boolean,
[key: any]: any,
},
refs?: Array<{
id: string
}>,
attachments?: Array<{
id: string,
type?: string,
}>,
tags?: {
[key: any]: any
},
};
export type Preset = {|
schemaVersion?: 1,
id: string,
name: string,
geometry: Array<("point" | "vertex" | "line" | "area" | "relation")>,
tags: {
[key: any]: any
},
addTags?: {
[key: any]: any
},
removeTags?: {
[key: any]: any
},
fields?: Array<string>,
additionalFields?: Array<string>,
icon?: string,
terms?: Array<string>,
sort?: number,
|};
/**
* @flow
* The flow types generated from the JSON Schema are not very strict. These
* manual types are more strict for fields, and are more useful in code
*/
export type Key = string | Array<string>
type BaseField = {|
// A unique id used to reference the field from presets
id: string,
// They key in a tags object that this field applies to. For nested
// properties, key can be an array e.g. for tags = { foo: { bar: 1 } } the key
// is ['foo', 'bar']
key: Key,
label?: string,
// Displayed as a placeholder or hint for the field: use for additional
// context or example responses for the user
placeholder?: string,
// Additional context about the field, e.g. hints about how to answer the
// question.
helperText?: string,
// If a field definition contains the property "universal": true, this field
// will appear in the "Add Field" list for all presets
universal?: boolean,
// Displayed, but cannot be edited
readonly?: boolean
|}
// type FieldType =
// | 'text'
// | 'number'
// | 'select_one'
// | 'select_multiple'
// | 'date'
// | 'datetime'
export type TextField = {
...BaseField,
type: 'text' | 'textarea' | 'localized',
appearance?: 'singleline' | 'multiline',
// Spaces are replaced with underscores
snake_case?: boolean
}
export type LinkField = {
...BaseField,
type: 'link'
}
export type NumberField = {
...BaseField,
type: 'number',
min_value?: number,
max_value?: number
}
export type SelectableFieldValue = number | string | boolean | null
export type LabeledSelectOption = {|
value: SelectableFieldValue,
label: string
|}
export type SelectOptions = Array<SelectableFieldValue | LabeledSelectOption>
export type SelectOneField = {
...BaseField,
type: 'select_one',
options: SelectOptions,
// User can enter their own reponse if not on the list (defaults to true on
// desktop, false on mobile)
other?: boolean,
// Spaces are replaced with underscores
snake_case?: boolean
}
export type SelectMultipleField = {
...$Exact<SelectOneField>,
type: 'select_multiple'
}
export type DateField = {
...BaseField,
type: 'date',
min_value?: string,
max_value?: string
}
export type DateTimeField = {
...BaseField,
type: 'datetime',
min_value?: string,
max_value?: string
}