elasticsearch-rolling-index-name-parser
Advanced tools
Comparing version 1.0.0 to 1.1.0
{ | ||
"name": "elasticsearch-rolling-index-name-parser", | ||
"version": "1.0.0", | ||
"version": "1.1.0", | ||
"description": "Parser for Elasticsearch rolling index names.", | ||
@@ -29,3 +29,3 @@ "main": "src/index.js", | ||
"eslint": "^5.13.0", | ||
"mocha": "^6.1.4", | ||
"mocha": "^6.2.0", | ||
"moment": "^2.24.0" | ||
@@ -32,0 +32,0 @@ }, |
@@ -0,2 +1,4 @@ | ||
[![CircleCI](https://circleci.com/gh/Brightspace/elasticsearch-rolling-index-name-parser.svg?style=svg)](https://circleci.com/gh/Brightspace/elasticsearch-rolling-index-name-parser) | ||
# elasticsearch-rolling-index-name-parser | ||
Parser for Elasticsearch rolling index names. |
@@ -8,3 +8,3 @@ const moment = require( 'moment' ); | ||
regex: '^(.+)-(\\d{4}-\\d{2}-\\d{2}-\\d{2})$', | ||
endOfUnit: 'hour' | ||
endOfCalculator: start => start.clone().endOf( 'hour' ) | ||
}, | ||
@@ -15,9 +15,18 @@ { | ||
regex: '^(.+)-(\\d{4}-\\d{2}-\\d{2})$', | ||
endOfUnit: 'day' | ||
endOfCalculator: start => start.clone().endOf( 'day' ) | ||
}, | ||
{ | ||
period: 'weekly', | ||
format: [ | ||
'GGGG-[w]WW', | ||
'GGGG-[W]WW' | ||
], | ||
regex: '^(.+)-(\\d{4}-[wW]\\d{2})$', | ||
endOfCalculator: start => start.clone().endOf( 'day' ).add( 6, 'day' ) | ||
}, | ||
{ | ||
period: 'monthly', | ||
format: 'YYYY-MM', | ||
regex: '^(.+)-(\\d{4}-\\d{2})$', | ||
endOfUnit: 'month' | ||
endOfCalculator: start => start.clone().endOf( 'month' ) | ||
} | ||
@@ -46,3 +55,3 @@ ]; | ||
const endMoment = startMoment.clone().endOf( datePattern.endOfUnit ); | ||
const endMoment = datePattern.endOfCalculator( startMoment ); | ||
@@ -60,2 +69,2 @@ return { | ||
}; | ||
}; | ||
}; |
@@ -55,2 +55,51 @@ const chai = require( 'chai' ); | ||
describe( 'when weekly pattern', function() { | ||
it( 'should parse lowercase w', function() { | ||
const result = rollingIndexNameParser( 'super_logs-2019-w33' ); | ||
assert( result, 'should parse index name' ); | ||
assert.equal( result.name, 'super_logs', 'name should be part before the date' ); | ||
assert.equal( result.period, 'weekly', 'period should be weekly' ); | ||
assert( moment.isMoment( result.startMoment ), 'start moment should be a moment' ); | ||
assert.equal( result.startMoment.toISOString(), '2019-08-12T00:00:00.000Z', 'should parse correct start moment' ); | ||
assert( moment.isMoment( result.endMoment ), 'end moment should be a moment' ); | ||
assert.equal( result.endMoment.toISOString(), '2019-08-18T23:59:59.999Z', 'should construct correct end moment' ); | ||
} ); | ||
it( 'should parse uppercase W', function() { | ||
const result = rollingIndexNameParser( 'super_logs-2019-W33' ); | ||
assert( result, 'should parse index name' ); | ||
assert.equal( result.name, 'super_logs', 'name should be part before the date' ); | ||
assert.equal( result.period, 'weekly', 'period should be weekly' ); | ||
assert( moment.isMoment( result.startMoment ), 'start moment should be a moment' ); | ||
assert.equal( result.startMoment.toISOString(), '2019-08-12T00:00:00.000Z', 'should parse correct start moment' ); | ||
assert( moment.isMoment( result.endMoment ), 'end moment should be a moment' ); | ||
assert.equal( result.endMoment.toISOString(), '2019-08-18T23:59:59.999Z', 'should construct correct end moment' ); | ||
} ); | ||
it( 'should parse week of year rules correctly', function() { | ||
const result = rollingIndexNameParser( 'weekly_logs-2009-W01' ); | ||
assert( result, 'should parse index name' ); | ||
assert.equal( result.name, 'weekly_logs', 'name should be part before the date' ); | ||
assert.equal( result.period, 'weekly', 'period should be weekly' ); | ||
assert( moment.isMoment( result.startMoment ), 'start moment should be a moment' ); | ||
assert.equal( result.startMoment.toISOString(), '2008-12-29T00:00:00.000Z', 'should parse correct start moment' ); | ||
assert( moment.isMoment( result.endMoment ), 'end moment should be a moment' ); | ||
assert.equal( result.endMoment.toISOString(), '2009-01-04T23:59:59.999Z', 'should construct correct end moment' ); | ||
} ); | ||
} ); | ||
it( 'should return null for non rolling index', function() { | ||
@@ -62,2 +111,26 @@ | ||
it( 'should return null for partial hourly index', function() { | ||
const result = rollingIndexNameParser( 'test-2018-04-23-12-abc' ); | ||
assert.isNull( result, 'should not parse' ); | ||
} ); | ||
it( 'should return null for partial daily index', function() { | ||
const result = rollingIndexNameParser( 'test-2018-04-23-abc' ); | ||
assert.isNull( result, 'should not parse' ); | ||
} ); | ||
it( 'should return null for partial weekly index', function() { | ||
const result = rollingIndexNameParser( 'test-2018-w12-abc' ); | ||
assert.isNull( result, 'should not parse' ); | ||
} ); | ||
it( 'should return null for partial monthly index', function() { | ||
const result = rollingIndexNameParser( 'test-2018-04-abc' ); | ||
assert.isNull( result, 'should not parse' ); | ||
} ); | ||
it( 'should return null for invalid hourly strings', function() { | ||
@@ -64,0 +137,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
10174
155
5