1.5.0 • Published 5 years ago

@wmfs/tymly-data-types v1.5.0

Weekly downloads
17
License
MIT
Repository
github
Last release
5 years ago

tymly-data-types

A work-in-progress library of data types often found in digital services.

Install

$ npm install @wmfs/tymly-data-types --save

Reference

The full list of 31 data-types currently defined by tymly-data-types is shown below.

  • The chances are you'll never need to use all these in any one scenario (that's where domains and categories can help narrow things down).
Data Item NameTitleCategoryDomain(s)Description
addressAddresstextlocationA string denoting an address which could be used to send a letter.
appointmentTimeAppointment timedateTimegeneralA date and time, often originally defined for a point in the future, to express when a particular event should occur.
booleanBooleanchoicegeneralA general boolean value of true or false.
choiceChoicechoicegeneralUse when a value should be taken from a known set, but no other data type is appropriate.
dateDatedateTimegeneralGeneral-purpose type for expressing a particular date (without a time component).
dateOfBirthDate of birthdateTimepeopleThe date (no time portion) for expressing the date a person was born.
dateTimeDate/timedateTimegeneralGeneral-purpose type for expressing a date and time.
emailEmailtextgeneral, computing, personUsed to convey an email address.
ethnicityEthnicitychoicepeopleUsed to express the ethnicity of a person.
eventTimeEvent timedateTimegeneralA date and time relating to when a particular event occurred.
frsCallsignCallsigntextfireA unique code to identify a vehicle, officer or other asset.
fsecCodeFSEC codechoicefireA code to help categorise a premise (as defined by Home Office).
genderGenderchoicepeopleFor describing a person's gender.
hostnameHostnametextcomputingUsed to convey an internet host name (RFC 5322).
idnHostnameIDN HostnametextcomputingUsed to convey an internationalized host name (RFC 5890).
integerIntegernumbergeneralGeneral-purpose type for expressing an integer value.
ipv4IPv4textcomputingUsed to convey an IPv4 address.
ipv6IPv6textcomputingUsed to convey an IPv6 address.
latLongLatitude/LongitudenumberlocationA pair of numbers denoting a point on the Earth's surface.
namePerson's nametextpeopleA data-type for expressing a person's name.
notesNotestextgeneralA data-item for expressing additional free-form notes often to provide deeper context for other data.
textTexttextgeneralGeneral-purpose type for expressing textual data (a mixture of letters, numbers and symbols).
timeTimedateTimegeneralGeneral-purpose type for expressing a time of day (without being related to any particular date).
titleTitlechoicepeopleTitles used to address people with (Miss, Mr. etc.)
uprnUPRNnumberlocation, fireUnique Property Reference Number as issued by Ordnance Survey as part of their gazetteer products.
uriURItextgeneral, computingA universal resource identifier (URI) according to RFC3986.
usrnUSRNnumberlocation, fireUnique Street Reference Number as issued by Ordnance Survey as part of their gazetteer products.
yesNoYes/NochoicegeneralA data type to express a Yes/No response.
yesNoNaYes/No/Not ApplicablechoicegeneralA data type to express a 'Yes', 'No' or 'Not applicable' response.
yesNoOtherYes/No/OtherchoicegeneralA data type to express a 'Yes', 'No' or 'Other' response.
yesNoUnknownYes/No/UnknownchoicegeneralA data type to express a 'Yes', 'No' or 'Unknown' response.

Domains

Data items are grouped into specialist domains, this helps narrow lists of data-items to just those suitable to the business domain(s) being addressed:

  • A single data-type can feature in multiple domains.
  • Note the general domain is considered the "default". Without any explicit configuration (i.e. no specialist domains are provided via options), the various methods in the tymly-data-types API will return data items to just those within the general domain.
Domain NameTitleDescription
computingComputingSpecialist data-types specific to computing.
fireFire ServiceData-types that are often used in the Fire and Rescue sector.
generalGeneralA set of general-purpose data types that can be used as a fallback if nothing more specific is available via other domains.
locationLocationTypes often found when dealing with geo-spatial data.
peoplePeopleCommonplace data-types relating to people (name, date of birth etc.)

Categories

As well as being grouped into one-or-more problem domains, each data-type is also assigned to a more functional category:

Category NameTitleDescription
choiceChoiceData items that relate to a finite, known set of values.
dateTimeDate/timeData items that relate to moments-in-time.
numberNumberData items that relate to a numeric value.
refReferenceData items whose value can relate to another entity
textTextData items that can contain a mixture of letters, numbers and symbols.

API

getDomains(options)

Use the getDomains() method to get an array of available domains.

Options

Supply options as an object with the following keys (note all of this is optional):

KeyDescription
filterStringIf provided will help filter domains to just those matching the supplied string.
sortControls the order of that the domains will be returned. A string of either seq (default) or name.

getCategories(options)

Use the getCategories() method to grab a list of categories.

Options

Supply options as an object with the following keys (note all of this is optional):

KeyDescription
filterStringIf provided will help filter categories to just those matching the supplied string.
sortControls the order of that the categories will be returned. A string of either seq (default) or name.
domainRestrictionAn array of strings denoting zero-or-more domain names. Only categories with one or more data-items in any of these domains will be returned. If no domainRestriction array is provided, then any categories used by data-items in just the general domain will be returned.

getDataTypes(options)

The main event, get a list of data-items as restricted by an object of optional options:

KeyDescription
filterStringIf provided will help filter data-items to just those matching the supplied string.
domainRestrictionOnly data-types belonging to any of the domains provided will be returned. Use just as described in the getCategories() method. If omitted, will be restricted to data-types in the general domain.
categoryAn optional string. Only data-types belonging to the supplied category name will be returned.
sortControls the order of that the data items will be returned. A string of either seq (default) or name.
  • This method returns an array of zero-or-more dataType objects. Take a look here to see the type of thing returned.

getDataTypeByName(dataTypeName)

Returns the specified data type.

getDataTypeNames()

Returns an array of data-type names.

getCategoryDefaultDataTypeNames()

Returns a key/value object where key is the name of a category and value is the name of a dataType considered the "default" for that category.

{
  "text": "text",
  "number": "integer",
  "dateTime": "dateTime",
  "choice": "choice"
}

getDataItemsByCategory(options)

Just like getDataTypes() but returns a key/value object where key is a category name and value is the associated array of data items.

Testing

$ npm test

Todo

  • Make into an online database! :smiley:
  • Modules (having everything in one big JSON file is a bit wrong).
  • Introduce versioning solution
  • Validation of domains, categories and data-types.
  • Especially integrity checks (data items belong to valid domains/categories), JSON Schema based?

License

MIT