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 :
effective_date: Date;
known_at: Date;
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') });
const mayConfiguration = historyService.getConfigurationAtDate({ date: new Date('2020-05-03') });
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') });
const mayConfiguration = historyService.getConfigurationAtDate({ date: new Date('2020-05-03') });