Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@georges-tech/tardis

Package Overview
Dependencies
Maintainers
6
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@georges-tech/tardis - npm Package Compare versions

Comparing version 1.1.0 to 1.2.0

3

dist/src/index.d.ts
import { TemporalDocument, HistoryService } from './types';
export declare function createHistoryService<T extends TemporalDocument>({ documents }: {
export declare function createHistoryService<T extends TemporalDocument>({ documents, date }: {
documents: T[];
date?: Date;
}): HistoryService<T>;

@@ -84,5 +84,8 @@ "use strict";

}
function createHistoryService({ documents }) {
const formattedDocuments = lodash_1.default.map(documents, (document, index) => (Object.assign(Object.assign({}, document), { __tardis_id: index + 1 })));
const configurationTimeline = _getConfigurationTimeline({ documents: formattedDocuments })
function createHistoryService({ documents, date }) {
const filteredAndFormattedDocuments = lodash_1.default.chain(documents)
.filter((document) => date ? moment_1.default(document.known_at).isSameOrBefore(date) : true)
.map((document, index) => (Object.assign(Object.assign({}, document), { __tardis_id: index + 1 })))
.value();
const configurationTimeline = _getConfigurationTimeline({ documents: filteredAndFormattedDocuments })
.map(item => lodash_1.default.omit(item, '__tardis_id'));

@@ -89,0 +92,0 @@ return {

{
"name": "@georges-tech/tardis",
"version": "1.1.0",
"version": "1.2.0",
"description": "Temporal property implementation for reading historized data",

@@ -5,0 +5,0 @@ "main": "dist/src/index.js",

@@ -43,2 +43,4 @@ # Tardis

While creating the service, you can provide a date to work on the related timeline.
## Example

@@ -72,1 +74,37 @@

```
### With given date
```ts
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
```

@@ -680,3 +680,71 @@ import chai from 'chai';

});
describe('looking the timeline in the past', () => {
it('should ignore documents that are known after the given date', () => {
const historyService = createHistoryService({
documents: [
{
known_at : new Date("2020-01-20"),
effective_date: new Date("2000-01-01"),
data: {
number: 1,
},
},
{
known_at : new Date("2020-02-20"),
effective_date : new Date("2019-03-01"),
data: {
number: 2,
},
},
{
known_at: new Date("2020-03-20"),
effective_date : new Date("2019-10-01"),
data: {
number: 3,
},
},
{
known_at: new Date("2020-05-20"),
effective_date : new Date("2019-01-01"),
data: {
number: 4,
},
},
],
date: new Date('2020-03-20'),
});
expect(
historyService.getConfigurationsOnDateRange({
startDate: new Date('2019-01-01'),
endDate: new Date('2019-12-31'),
})
).to.deep.equal([
{
known_at : new Date("2020-01-20"),
effective_date: new Date("2000-01-01"),
end_date : new Date("2019-03-01"),
data: {
number: 1,
},
},{
known_at : new Date("2020-02-20"),
effective_date : new Date("2019-03-01"),
end_date : new Date("2019-10-01"),
data: {
number: 2,
},
},
{
known_at: new Date("2020-03-20"),
effective_date : new Date("2019-10-01"),
end_date : undefined,
data: {
number: 3,
},
}]);
});
})
});
});
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc