Skip to content

Improve exports of spatial and temporal types #355

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 17, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 39 additions & 29 deletions src/v1/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ const error = {
};

/**
* Object containing functions for work with {@link Integer} objects.
* Object containing functions to work with {@link Integer} objects.
*/
const integer = {
toNumber,
Expand All @@ -244,26 +244,16 @@ const integer = {
};

/**
* @private
* Object containing functions to work with spatial types, like {@link Point}.
*/
const forExport = {
driver,
int,
isInt,
integer,
Neo4jError,
auth,
types,
session,
error,
Point,
isPoint,
Date,
DateTime,
Duration,
LocalDateTime,
LocalTime,
Time,
const spatial = {
isPoint
};

/**
* Object containing functions to work with temporal types, like {@link Time} or {@link Duration}.
*/
const temporal = {
isDuration,
isLocalTime,
isTime,
Expand All @@ -272,29 +262,49 @@ const forExport = {
isDateTime
};

export {

/**
* @private
*/
const forExport = {
driver,
int,
isInt,
isPoint,
isDuration,
isLocalTime,
isTime,
isDate,
isLocalDateTime,
isDateTime,
integer,
Neo4jError,
auth,
types,
session,
error,
Point,
spatial,
temporal
};

export {
driver,
int,
isInt,
isPoint,
Date,
DateTime,
Duration,
LocalDateTime,
LocalTime,
Time,
isDuration,
isLocalTime,
isTime,
isDate,
isLocalDateTime,
isDateTime
isDateTime,
integer,
Neo4jError,
auth,
types,
session,
error,
spatial,
temporal
};
export default forExport;
9 changes: 4 additions & 5 deletions test/internal/temporal-util.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@

import {int} from '../../src/v1/integer';
import * as util from '../../src/v1/internal/temporal-util';
import {Date} from '../../src/v1/temporal-types';
import {LocalDateTime, LocalTime} from '../../src/v1';
import {types} from '../../src/v1';

describe('temporal-util', () => {

Expand Down Expand Up @@ -120,13 +119,13 @@ describe('temporal-util', () => {
});

function date(year, month, day) {
return new Date(int(year), int(month), int(day));
return new types.Date(int(year), int(month), int(day));
}

function localTime(hour, minute, second, nanosecond) {
return new LocalTime(int(hour), int(minute), int(second), int(nanosecond));
return new types.LocalTime(int(hour), int(minute), int(second), int(nanosecond));
}

function localDateTime(year, month, day, hour, minute, second, nanosecond) {
return new LocalDateTime(int(year), int(month), int(day), int(hour), int(minute), int(second), int(nanosecond));
return new types.LocalDateTime(int(year), int(month), int(day), int(hour), int(minute), int(second), int(nanosecond));
}
9 changes: 8 additions & 1 deletion test/types/v1/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* limitations under the License.
*/

import v1, {auth, AuthToken, Config, driver, error, session} from "../../../types/v1/index";
import v1, {auth, AuthToken, Config, driver, error, session, spatial, temporal} from "../../../types/v1/index";

import Driver from "../../../types/v1/driver";

Expand Down Expand Up @@ -63,3 +63,10 @@ const serviceUnavailable2: string = v1.error.SERVICE_UNAVAILABLE;
const sessionExpired2: string = v1.error.SESSION_EXPIRED;
const protocolError2: string = v1.error.PROTOCOL_ERROR;

const isNeo4jPoint: boolean = spatial.isPoint({});
const isNeo4jDate: boolean = temporal.isDate({});
const isNeo4jDateTime: boolean = temporal.isDateTime({});
const isNeo4jDuration: boolean = temporal.isDuration({});
const isNeo4jLocalDateTime: boolean = temporal.isLocalDateTime({});
const isNeo4jLocalTime: boolean = temporal.isLocalTime({});
const isNeo4jTime: boolean = temporal.isTime({});
44 changes: 22 additions & 22 deletions test/v1/temporal-types.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ describe('temporal-types', () => {
}
session = driverWithNativeNumbers.session();

testSendReceiveTemporalValue(new neo4j.Duration(4, 15, 931, 99953), done);
testSendReceiveTemporalValue(new neo4j.types.Duration(4, 15, 931, 99953), done);
});

it('should send and receive array of Duration', done => {
Expand Down Expand Up @@ -154,7 +154,7 @@ describe('temporal-types', () => {
}
session = driverWithNativeNumbers.session();

testSendReceiveTemporalValue(new neo4j.LocalTime(12, 32, 56, 12345), done);
testSendReceiveTemporalValue(new neo4j.types.LocalTime(12, 32, 56, 12345), done);
});

it('should send and receive random LocalTime', done => {
Expand Down Expand Up @@ -206,7 +206,7 @@ describe('temporal-types', () => {
}
session = driverWithNativeNumbers.session();

testSendReceiveTemporalValue(new neo4j.Time(22, 19, 32, 18381, MAX_TIME_ZONE_OFFSET), done);
testSendReceiveTemporalValue(new neo4j.types.Time(22, 19, 32, 18381, MAX_TIME_ZONE_OFFSET), done);
});

it('should send and receive random Time', done => {
Expand Down Expand Up @@ -258,7 +258,7 @@ describe('temporal-types', () => {
}
session = driverWithNativeNumbers.session();

testSendReceiveTemporalValue(new neo4j.Date(1923, 8, 14), done);
testSendReceiveTemporalValue(new neo4j.types.Date(1923, 8, 14), done);
});

it('should send and receive random Date', done => {
Expand Down Expand Up @@ -310,7 +310,7 @@ describe('temporal-types', () => {
}
session = driverWithNativeNumbers.session();

testSendReceiveTemporalValue(new neo4j.LocalDateTime(2045, 9, 1, 11, 25, 25, 911), done);
testSendReceiveTemporalValue(new neo4j.types.LocalDateTime(2045, 9, 1, 11, 25, 25, 911), done);
});

it('should send and receive random LocalDateTime', done => {
Expand Down Expand Up @@ -362,7 +362,7 @@ describe('temporal-types', () => {
}
session = driverWithNativeNumbers.session();

testSendReceiveTemporalValue(new neo4j.DateTime(2022, 2, 7, 17, 15, 59, 12399, MAX_TIME_ZONE_OFFSET, null), done);
testSendReceiveTemporalValue(new neo4j.types.DateTime(2022, 2, 7, 17, 15, 59, 12399, MAX_TIME_ZONE_OFFSET, null), done);
});

it('should send and receive random DateTime with zone offset', done => {
Expand Down Expand Up @@ -414,7 +414,7 @@ describe('temporal-types', () => {
}
session = driverWithNativeNumbers.session();

testSendReceiveTemporalValue(new neo4j.DateTime(2011, 11, 25, 23, 59, 59, 192378, null, 'Europe/Stockholm'), done);
testSendReceiveTemporalValue(new neo4j.types.DateTime(2011, 11, 25, 23, 59, 59, 192378, null, 'Europe/Stockholm'), done);
});

it('should send and receive random DateTime with zone id', done => {
Expand Down Expand Up @@ -599,30 +599,30 @@ describe('temporal-types', () => {

function randomDateTimeWithZoneOffset() {
const dateTime = randomDstSafeLocalDateTime();
return new neo4j.DateTime(dateTime.year, dateTime.month, dateTime.day, dateTime.hour, dateTime.minute, dateTime.second, dateTime.nanosecond,
return new neo4j.types.DateTime(dateTime.year, dateTime.month, dateTime.day, dateTime.hour, dateTime.minute, dateTime.second, dateTime.nanosecond,
randomZoneOffsetSeconds(), null);
}

function randomDateTimeWithZoneId() {
const dateTime = randomDstSafeLocalDateTime();
return new neo4j.DateTime(dateTime.year, dateTime.month, dateTime.day, dateTime.hour, dateTime.minute, dateTime.second, dateTime.nanosecond,
return new neo4j.types.DateTime(dateTime.year, dateTime.month, dateTime.day, dateTime.hour, dateTime.minute, dateTime.second, dateTime.nanosecond,
null, randomZoneId());
}

function randomDstSafeLocalDateTime() {
const date = randomDate();
const time = randomDstSafeLocalTime();
return new neo4j.LocalDateTime(date.year, date.month, date.day, time.hour, time.minute, time.second, time.nanosecond);
return new neo4j.types.LocalDateTime(date.year, date.month, date.day, time.hour, time.minute, time.second, time.nanosecond);
}

function randomLocalDateTime() {
const date = randomDate();
const time = randomLocalTime();
return new neo4j.LocalDateTime(date.year, date.month, date.day, time.hour, time.minute, time.second, time.nanosecond);
return new neo4j.types.LocalDateTime(date.year, date.month, date.day, time.hour, time.minute, time.second, time.nanosecond);
}

function randomDate() {
return new neo4j.Date(
return new neo4j.types.Date(
randomInt(MIN_YEAR, MAX_YEAR),
randomInt(1, 12),
randomInt(1, 28)
Expand All @@ -631,11 +631,11 @@ describe('temporal-types', () => {

function randomTime() {
const localTime = randomLocalTime();
return new neo4j.Time(localTime.hour, localTime.minute, localTime.second, localTime.nanosecond, randomZoneOffsetSeconds());
return new neo4j.types.Time(localTime.hour, localTime.minute, localTime.second, localTime.nanosecond, randomZoneOffsetSeconds());
}

function randomLocalTime() {
return new neo4j.LocalTime(
return new neo4j.types.LocalTime(
randomInt(0, 23),
randomInt(0, 59),
randomInt(0, 59),
Expand All @@ -644,7 +644,7 @@ describe('temporal-types', () => {
}

function randomDstSafeLocalTime() {
return new neo4j.LocalTime(
return new neo4j.types.LocalTime(
randomInt(4, 23), // do not generate hours in range where DST adjustment happens
randomInt(0, 59),
randomInt(0, 59),
Expand All @@ -662,33 +662,33 @@ describe('temporal-types', () => {
}

function duration(months, days, seconds, nanoseconds) {
return new neo4j.Duration(neo4j.int(months), neo4j.int(days), neo4j.int(seconds), neo4j.int(nanoseconds));
return new neo4j.types.Duration(neo4j.int(months), neo4j.int(days), neo4j.int(seconds), neo4j.int(nanoseconds));
}

function localTime(hour, minute, second, nanosecond) {
return new neo4j.LocalTime(neo4j.int(hour), neo4j.int(minute), neo4j.int(second), neo4j.int(nanosecond));
return new neo4j.types.LocalTime(neo4j.int(hour), neo4j.int(minute), neo4j.int(second), neo4j.int(nanosecond));
}

function time(hour, minute, second, nanosecond, offsetSeconds) {
return new neo4j.Time(neo4j.int(hour), neo4j.int(minute), neo4j.int(second), neo4j.int(nanosecond), neo4j.int(offsetSeconds));
return new neo4j.types.Time(neo4j.int(hour), neo4j.int(minute), neo4j.int(second), neo4j.int(nanosecond), neo4j.int(offsetSeconds));
}

function date(year, month, day) {
return new neo4j.Date(neo4j.int(year), neo4j.int(month), neo4j.int(day));
return new neo4j.types.Date(neo4j.int(year), neo4j.int(month), neo4j.int(day));
}

function localDateTime(year, month, day, hour, minute, second, nanosecond) {
return new neo4j.LocalDateTime(neo4j.int(year), neo4j.int(month), neo4j.int(day),
return new neo4j.types.LocalDateTime(neo4j.int(year), neo4j.int(month), neo4j.int(day),
neo4j.int(hour), neo4j.int(minute), neo4j.int(second), neo4j.int(nanosecond));
}

function dateTimeWithZoneOffset(year, month, day, hour, minute, second, nanosecond, offsetSeconds) {
return new neo4j.DateTime(neo4j.int(year), neo4j.int(month), neo4j.int(day),
return new neo4j.types.DateTime(neo4j.int(year), neo4j.int(month), neo4j.int(day),
neo4j.int(hour), neo4j.int(minute), neo4j.int(second), neo4j.int(nanosecond), neo4j.int(offsetSeconds), null);
}

function dateTimeWithZoneId(year, month, day, hour, minute, second, nanosecond, zoneId) {
return new neo4j.DateTime(neo4j.int(year), neo4j.int(month), neo4j.int(day),
return new neo4j.types.DateTime(neo4j.int(year), neo4j.int(month), neo4j.int(day),
neo4j.int(hour), neo4j.int(minute), neo4j.int(second), neo4j.int(nanosecond), null, zoneId);
}

Expand Down
17 changes: 17 additions & 0 deletions types/v1/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,19 @@ declare const integer: {
inSafeRange: typeof inSafeRange;
};

declare const spatial: {
isPoint: typeof isPoint;
};

declare const temporal: {
isDuration: typeof isDuration;
isLocalTime: typeof isLocalTime;
isTime: typeof isTime;
isDate: typeof isDate;
isLocalDateTime: typeof isLocalDateTime;
isDateTime: typeof isDateTime;
};

/*
Both default and non-default exports declare all visible types so that they can be used in client code like this:

Expand All @@ -101,6 +114,8 @@ declare const forExport: {
types: typeof types;
session: typeof session;
error: typeof error;
spatial: typeof spatial;
temporal: typeof temporal;
Driver: Driver;
AuthToken: AuthToken;
Config: Config;
Expand Down Expand Up @@ -152,6 +167,8 @@ export {
types,
session,
error,
spatial,
temporal,
Driver,
AuthToken,
Config,
Expand Down