@georges-tech/tardis
v1.2.1
Published
Temporal property implementation for reading historized data
Downloads
25,533
Readme
Tardis
Temporal property implementation for reading historized data.
Installation
npm install @georges-tech/tardis
Usage
You create a Tardis service through createHistoryService
by providing an array of documents that must contain
the following properties :
/**
* Date at which the configuration starts to be valid
*/
effective_date: Date;
/**
* Date at which the new configuration has been created
*/
known_at: Date;
/**
* Optional end date for limited time configurations
*/
end_date?: Date;
You can add as much properties as you like, depending on your use case, that will be returned by services.
Documents may contain a computed end_date
, being the next effective document date if it exists. Otherwise, it
is undefined
.
While creating the service, you can provide a date to work on the related timeline.
Example
import tardis from '@georges-tech/tardis';
const documents = [{
effective_date: new Date('2020-01-01'),
known_at: new Date('2020-05-01'),
data: {
value: 'old',
}
}, {
effective_date: new Date('2020-03-01'),
known_at: new Date('2020-10-01'),
data: {
value: 'new',
}
}]
const historyService = tardis.createHistoryService({ documents });
const januaryConfiguration = historyService.getConfigurationAtDate({ date: new Date('2020-01-03') });
// januaryConfiguration.data.value = 'old'
// januaryConfiguration.end_date = new Date('2020-03-01')
const mayConfiguration = historyService.getConfigurationAtDate({ date: new Date('2020-05-03') });
// mayConfiguration.data.value = 'new'
// mayConfiguration.end_date = undefined
With given date
import tardis from '@georges-tech/tardis';
const documents = [{
effective_date: new Date('2020-01-01'),
known_at: new Date('2020-05-01'),
data: {
value: 'old',
}
}, {
effective_date: new Date('2020-03-01'),
known_at: new Date('2020-10-01'),
data: {
value: 'new',
},
{
effective_date: new Date('2020-04-01'),
known_at: new Date('2020-12-01'),
data: {
value: 'new 2',
}
}]
const historyService = tardis.createHistoryService({ documents, date: new Date('2020-11-01') });
const januaryConfiguration = historyService.getConfigurationAtDate({ date: new Date('2020-01-03') });
// januaryConfiguration.data.value = 'old'
// januaryConfiguration.end_date = new Date('2020-03-01')
const mayConfiguration = historyService.getConfigurationAtDate({ date: new Date('2020-05-03') });
// mayConfiguration.data.value = 'new'
// mayConfiguration.end_date = undefined
// Here we keep the configuration known on 01/10 because on the given date we did not yet know the "new2" configuration