@neo4j-labs/experimental-query-api-wrapper
Advanced tools
Comparing version
@@ -165,13 +165,41 @@ /** | ||
// 12:50:35.556+01:00 | ||
// 12:50:35+01:00 | ||
// 12:50:35Z | ||
const [hourStr, minuteString, secondNanosecondAndOffsetString, offsetMinuteString] = value.split(':'); | ||
const [secondStr, nanosecondAndOffsetString] = secondNanosecondAndOffsetString.split('.'); | ||
// @ts-expect-error | ||
const [nanosecondString, offsetHourString, isPositive] = nanosecondAndOffsetString.indexOf('+') >= 0 ? | ||
[...nanosecondAndOffsetString.split('+'), true] : (nanosecondAndOffsetString.indexOf('-') >= 0 ? | ||
[...nanosecondAndOffsetString.split('-'), false] : (nanosecondAndOffsetString.indexOf('Z') >= 0 ? | ||
[nanosecondAndOffsetString.slice(0, nanosecondAndOffsetString.length - 1), undefined, true] : | ||
[nanosecondAndOffsetString.slice(0, nanosecondAndOffsetString.length - 1), '0', true])); | ||
let nanosecond = int(nanosecondString.padEnd(9, '0')); | ||
if (offsetHourString != null) { | ||
const timeZoneOffsetInSeconds = int(offsetHourString).multiply(60).add(int(offsetMinuteString)).multiply(60).multiply(isPositive ? 1 : -1); | ||
let [secondStr, nanosecondAndOffsetString] = secondNanosecondAndOffsetString.split('.'); | ||
let [nanosecondString, offsetHourString, isPositive, hasOffset] = ['0', '0', true, true]; | ||
if (nanosecondAndOffsetString !== undefined) { | ||
if (nanosecondAndOffsetString.indexOf('+') >= 0) { | ||
[nanosecondString, offsetHourString] = [...nanosecondAndOffsetString.split('+')]; | ||
} | ||
else if (nanosecondAndOffsetString.indexOf('-') >= 0) { | ||
[nanosecondString, offsetHourString] = [...nanosecondAndOffsetString.split('-')]; | ||
isPositive = false; | ||
} | ||
else if (nanosecondAndOffsetString.indexOf('Z') >= 0) { | ||
[nanosecondString] = [...nanosecondAndOffsetString.split('Z')]; | ||
} | ||
else { | ||
hasOffset = false; | ||
if (nanosecondAndOffsetString.indexOf('[')) { | ||
[nanosecondString] = [...nanosecondAndOffsetString.split('[')]; | ||
} | ||
} | ||
} | ||
else { | ||
if (secondStr.indexOf('+') >= 0) { | ||
[secondStr, offsetHourString] = [...secondStr.split('+')]; | ||
} | ||
else if (secondStr.indexOf('-') >= 0) { | ||
[secondStr, offsetHourString] = [...secondStr.split('-')]; | ||
isPositive = false; | ||
} | ||
else if (secondStr.indexOf('Z') < 0) { | ||
hasOffset = false; | ||
} | ||
} | ||
secondStr = secondStr.substring(0, 2); | ||
const nanosecond = int(nanosecondString.padEnd(9, '0')); | ||
if (hasOffset) { | ||
const timeZoneOffsetInSeconds = int(offsetHourString).multiply(60).add(int(offsetMinuteString ?? '0')).multiply(60).multiply(isPositive ? 1 : -1); | ||
return new Time(this._decodeInteger(hourStr), this._decodeInteger(minuteString), this._decodeInteger(secondStr), this._normalizeInteger(nanosecond), this._normalizeInteger(timeZoneOffsetInSeconds)); | ||
@@ -221,13 +249,10 @@ } | ||
// P14DT16H12M | ||
// Duration is PnW | ||
const durationStringWithP = value.slice(1, value.length); | ||
if (durationStringWithP.endsWith('W')) { | ||
const weeksString = durationStringWithP.slice(0, durationStringWithP.length - 1); | ||
const weeks = this._decodeInteger(weeksString); | ||
throw newError('Duration in weeks are not supported yet', error.PROTOCOL_ERROR); | ||
} | ||
let month = '0'; | ||
let week = '0'; | ||
let day = '0'; | ||
let second = '0'; | ||
let nanosecond = '0'; | ||
let hour = '0'; | ||
let minute = '0'; | ||
let currentNumber = ''; | ||
@@ -242,10 +267,20 @@ let timePart = false; | ||
case 'M': | ||
// minutes | ||
if (timePart) { | ||
throw newError(`Unexpected Duration component ${ch} in time part`, error.PROTOCOL_ERROR); | ||
minute = currentNumber; | ||
// months | ||
} | ||
month = currentNumber; | ||
else { | ||
month = currentNumber; | ||
} | ||
break; | ||
case 'W': | ||
if (timePart) { | ||
throw newError(`Duration is not well formatted. Unexpected Duration component ${ch} in time part`, error.PROTOCOL_ERROR); | ||
} | ||
week = currentNumber; | ||
break; | ||
case 'D': | ||
if (timePart) { | ||
throw newError(`Unexpected Duration component ${ch} in time part`, error.PROTOCOL_ERROR); | ||
throw newError(`Duration is not well formatted. Unexpected Duration component ${ch} in time part`, error.PROTOCOL_ERROR); | ||
} | ||
@@ -256,3 +291,3 @@ day = currentNumber; | ||
if (!timePart) { | ||
throw newError(`Unexpected Duration component ${ch} in date part`, error.PROTOCOL_ERROR); | ||
throw newError(`Duration is not well formatted. Unexpected Duration component ${ch} in date part`, error.PROTOCOL_ERROR); | ||
} | ||
@@ -262,2 +297,8 @@ const nanosecondSeparator = currentNumber.includes(',') ? ',' : '.'; | ||
break; | ||
case 'H': | ||
if (!timePart) { | ||
throw newError(`Duration is not well formatted. Unexpected Duration component ${ch} in date part`, error.PROTOCOL_ERROR); | ||
} | ||
hour = currentNumber; | ||
break; | ||
case 'T': | ||
@@ -267,3 +308,3 @@ timePart = true; | ||
default: | ||
throw newError(`Unexpected Duration component ${ch}`, error.PROTOCOL_ERROR); | ||
throw newError(`Duration is not well formatted. Unexpected Duration component ${ch}`, error.PROTOCOL_ERROR); | ||
} | ||
@@ -273,4 +314,12 @@ currentNumber = ''; | ||
} | ||
const secondsInt = int(hour) | ||
.multiply(60) | ||
.add(minute) | ||
.multiply(60) | ||
.add(second); | ||
const dayInt = int(week) | ||
.multiply(7) | ||
.add(day); | ||
const nanosecondString = nanosecond ?? '0'; | ||
return new Duration(this._decodeInteger(month), this._decodeInteger(day), this._decodeInteger(second), this._decodeInteger(nanosecondString.padEnd(9, '0'))); | ||
return new Duration(this._decodeInteger(month), this._normalizeInteger(dayInt), this._normalizeInteger(secondsInt), this._decodeInteger(nanosecondString.padEnd(9, '0'))); | ||
} | ||
@@ -277,0 +326,0 @@ _decodeMap(value) { |
{ | ||
"name": "@neo4j-labs/experimental-query-api-wrapper", | ||
"version": "0.0.1-alpha04", | ||
"version": "0.0.1-alpha05", | ||
"description": "Experimental wrapper library to access Neo4j Database using Query API with a neo4j-driver-like interface.", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
110256
1.56%2416
2.07%