mapeo-schema
Version:
JSON schema and flow types for Mapeo
96 lines (82 loc) • 2.31 kB
Flow
/**
* @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
}