Skip to content

Commit f8d3b8a

Browse files
authored
Merge pull request #355 from lutovich/1.6-improve-exports
Improve exports of spatial and temporal types
2 parents 9a7f2b2 + eff3451 commit f8d3b8a

File tree

5 files changed

+90
-57
lines changed

5 files changed

+90
-57
lines changed

src/v1/index.js

+39-29
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ const error = {
235235
};
236236

237237
/**
238-
* Object containing functions for work with {@link Integer} objects.
238+
* Object containing functions to work with {@link Integer} objects.
239239
*/
240240
const integer = {
241241
toNumber,
@@ -244,26 +244,16 @@ const integer = {
244244
};
245245

246246
/**
247-
* @private
247+
* Object containing functions to work with spatial types, like {@link Point}.
248248
*/
249-
const forExport = {
250-
driver,
251-
int,
252-
isInt,
253-
integer,
254-
Neo4jError,
255-
auth,
256-
types,
257-
session,
258-
error,
259-
Point,
260-
isPoint,
261-
Date,
262-
DateTime,
263-
Duration,
264-
LocalDateTime,
265-
LocalTime,
266-
Time,
249+
const spatial = {
250+
isPoint
251+
};
252+
253+
/**
254+
* Object containing functions to work with temporal types, like {@link Time} or {@link Duration}.
255+
*/
256+
const temporal = {
267257
isDuration,
268258
isLocalTime,
269259
isTime,
@@ -272,29 +262,49 @@ const forExport = {
272262
isDateTime
273263
};
274264

275-
export {
265+
266+
/**
267+
* @private
268+
*/
269+
const forExport = {
276270
driver,
277271
int,
278272
isInt,
273+
isPoint,
274+
isDuration,
275+
isLocalTime,
276+
isTime,
277+
isDate,
278+
isLocalDateTime,
279+
isDateTime,
279280
integer,
280281
Neo4jError,
281282
auth,
282283
types,
283284
session,
284285
error,
285-
Point,
286+
spatial,
287+
temporal
288+
};
289+
290+
export {
291+
driver,
292+
int,
293+
isInt,
286294
isPoint,
287-
Date,
288-
DateTime,
289-
Duration,
290-
LocalDateTime,
291-
LocalTime,
292-
Time,
293295
isDuration,
294296
isLocalTime,
295297
isTime,
296298
isDate,
297299
isLocalDateTime,
298-
isDateTime
300+
isDateTime,
301+
integer,
302+
Neo4jError,
303+
auth,
304+
types,
305+
session,
306+
error,
307+
spatial,
308+
temporal
299309
};
300310
export default forExport;

test/internal/temporal-util.test.js

+4-5
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@
1919

2020
import {int} from '../../src/v1/integer';
2121
import * as util from '../../src/v1/internal/temporal-util';
22-
import {Date} from '../../src/v1/temporal-types';
23-
import {LocalDateTime, LocalTime} from '../../src/v1';
22+
import {types} from '../../src/v1';
2423

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

@@ -120,13 +119,13 @@ describe('temporal-util', () => {
120119
});
121120

122121
function date(year, month, day) {
123-
return new Date(int(year), int(month), int(day));
122+
return new types.Date(int(year), int(month), int(day));
124123
}
125124

126125
function localTime(hour, minute, second, nanosecond) {
127-
return new LocalTime(int(hour), int(minute), int(second), int(nanosecond));
126+
return new types.LocalTime(int(hour), int(minute), int(second), int(nanosecond));
128127
}
129128

130129
function localDateTime(year, month, day, hour, minute, second, nanosecond) {
131-
return new LocalDateTime(int(year), int(month), int(day), int(hour), int(minute), int(second), int(nanosecond));
130+
return new types.LocalDateTime(int(year), int(month), int(day), int(hour), int(minute), int(second), int(nanosecond));
132131
}

test/types/v1/index.test.ts

+8-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
* limitations under the License.
1818
*/
1919

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

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

@@ -63,3 +63,10 @@ const serviceUnavailable2: string = v1.error.SERVICE_UNAVAILABLE;
6363
const sessionExpired2: string = v1.error.SESSION_EXPIRED;
6464
const protocolError2: string = v1.error.PROTOCOL_ERROR;
6565

66+
const isNeo4jPoint: boolean = spatial.isPoint({});
67+
const isNeo4jDate: boolean = temporal.isDate({});
68+
const isNeo4jDateTime: boolean = temporal.isDateTime({});
69+
const isNeo4jDuration: boolean = temporal.isDuration({});
70+
const isNeo4jLocalDateTime: boolean = temporal.isLocalDateTime({});
71+
const isNeo4jLocalTime: boolean = temporal.isLocalTime({});
72+
const isNeo4jTime: boolean = temporal.isTime({});

test/v1/temporal-types.test.js

+22-22
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ describe('temporal-types', () => {
110110
}
111111
session = driverWithNativeNumbers.session();
112112

113-
testSendReceiveTemporalValue(new neo4j.Duration(4, 15, 931, 99953), done);
113+
testSendReceiveTemporalValue(new neo4j.types.Duration(4, 15, 931, 99953), done);
114114
});
115115

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

157-
testSendReceiveTemporalValue(new neo4j.LocalTime(12, 32, 56, 12345), done);
157+
testSendReceiveTemporalValue(new neo4j.types.LocalTime(12, 32, 56, 12345), done);
158158
});
159159

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

209-
testSendReceiveTemporalValue(new neo4j.Time(22, 19, 32, 18381, MAX_TIME_ZONE_OFFSET), done);
209+
testSendReceiveTemporalValue(new neo4j.types.Time(22, 19, 32, 18381, MAX_TIME_ZONE_OFFSET), done);
210210
});
211211

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

261-
testSendReceiveTemporalValue(new neo4j.Date(1923, 8, 14), done);
261+
testSendReceiveTemporalValue(new neo4j.types.Date(1923, 8, 14), done);
262262
});
263263

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

313-
testSendReceiveTemporalValue(new neo4j.LocalDateTime(2045, 9, 1, 11, 25, 25, 911), done);
313+
testSendReceiveTemporalValue(new neo4j.types.LocalDateTime(2045, 9, 1, 11, 25, 25, 911), done);
314314
});
315315

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

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

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

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

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

600600
function randomDateTimeWithZoneOffset() {
601601
const dateTime = randomDstSafeLocalDateTime();
602-
return new neo4j.DateTime(dateTime.year, dateTime.month, dateTime.day, dateTime.hour, dateTime.minute, dateTime.second, dateTime.nanosecond,
602+
return new neo4j.types.DateTime(dateTime.year, dateTime.month, dateTime.day, dateTime.hour, dateTime.minute, dateTime.second, dateTime.nanosecond,
603603
randomZoneOffsetSeconds(), null);
604604
}
605605

606606
function randomDateTimeWithZoneId() {
607607
const dateTime = randomDstSafeLocalDateTime();
608-
return new neo4j.DateTime(dateTime.year, dateTime.month, dateTime.day, dateTime.hour, dateTime.minute, dateTime.second, dateTime.nanosecond,
608+
return new neo4j.types.DateTime(dateTime.year, dateTime.month, dateTime.day, dateTime.hour, dateTime.minute, dateTime.second, dateTime.nanosecond,
609609
null, randomZoneId());
610610
}
611611

612612
function randomDstSafeLocalDateTime() {
613613
const date = randomDate();
614614
const time = randomDstSafeLocalTime();
615-
return new neo4j.LocalDateTime(date.year, date.month, date.day, time.hour, time.minute, time.second, time.nanosecond);
615+
return new neo4j.types.LocalDateTime(date.year, date.month, date.day, time.hour, time.minute, time.second, time.nanosecond);
616616
}
617617

618618
function randomLocalDateTime() {
619619
const date = randomDate();
620620
const time = randomLocalTime();
621-
return new neo4j.LocalDateTime(date.year, date.month, date.day, time.hour, time.minute, time.second, time.nanosecond);
621+
return new neo4j.types.LocalDateTime(date.year, date.month, date.day, time.hour, time.minute, time.second, time.nanosecond);
622622
}
623623

624624
function randomDate() {
625-
return new neo4j.Date(
625+
return new neo4j.types.Date(
626626
randomInt(MIN_YEAR, MAX_YEAR),
627627
randomInt(1, 12),
628628
randomInt(1, 28)
@@ -631,11 +631,11 @@ describe('temporal-types', () => {
631631

632632
function randomTime() {
633633
const localTime = randomLocalTime();
634-
return new neo4j.Time(localTime.hour, localTime.minute, localTime.second, localTime.nanosecond, randomZoneOffsetSeconds());
634+
return new neo4j.types.Time(localTime.hour, localTime.minute, localTime.second, localTime.nanosecond, randomZoneOffsetSeconds());
635635
}
636636

637637
function randomLocalTime() {
638-
return new neo4j.LocalTime(
638+
return new neo4j.types.LocalTime(
639639
randomInt(0, 23),
640640
randomInt(0, 59),
641641
randomInt(0, 59),
@@ -644,7 +644,7 @@ describe('temporal-types', () => {
644644
}
645645

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

664664
function duration(months, days, seconds, nanoseconds) {
665-
return new neo4j.Duration(neo4j.int(months), neo4j.int(days), neo4j.int(seconds), neo4j.int(nanoseconds));
665+
return new neo4j.types.Duration(neo4j.int(months), neo4j.int(days), neo4j.int(seconds), neo4j.int(nanoseconds));
666666
}
667667

668668
function localTime(hour, minute, second, nanosecond) {
669-
return new neo4j.LocalTime(neo4j.int(hour), neo4j.int(minute), neo4j.int(second), neo4j.int(nanosecond));
669+
return new neo4j.types.LocalTime(neo4j.int(hour), neo4j.int(minute), neo4j.int(second), neo4j.int(nanosecond));
670670
}
671671

672672
function time(hour, minute, second, nanosecond, offsetSeconds) {
673-
return new neo4j.Time(neo4j.int(hour), neo4j.int(minute), neo4j.int(second), neo4j.int(nanosecond), neo4j.int(offsetSeconds));
673+
return new neo4j.types.Time(neo4j.int(hour), neo4j.int(minute), neo4j.int(second), neo4j.int(nanosecond), neo4j.int(offsetSeconds));
674674
}
675675

676676
function date(year, month, day) {
677-
return new neo4j.Date(neo4j.int(year), neo4j.int(month), neo4j.int(day));
677+
return new neo4j.types.Date(neo4j.int(year), neo4j.int(month), neo4j.int(day));
678678
}
679679

680680
function localDateTime(year, month, day, hour, minute, second, nanosecond) {
681-
return new neo4j.LocalDateTime(neo4j.int(year), neo4j.int(month), neo4j.int(day),
681+
return new neo4j.types.LocalDateTime(neo4j.int(year), neo4j.int(month), neo4j.int(day),
682682
neo4j.int(hour), neo4j.int(minute), neo4j.int(second), neo4j.int(nanosecond));
683683
}
684684

685685
function dateTimeWithZoneOffset(year, month, day, hour, minute, second, nanosecond, offsetSeconds) {
686-
return new neo4j.DateTime(neo4j.int(year), neo4j.int(month), neo4j.int(day),
686+
return new neo4j.types.DateTime(neo4j.int(year), neo4j.int(month), neo4j.int(day),
687687
neo4j.int(hour), neo4j.int(minute), neo4j.int(second), neo4j.int(nanosecond), neo4j.int(offsetSeconds), null);
688688
}
689689

690690
function dateTimeWithZoneId(year, month, day, hour, minute, second, nanosecond, zoneId) {
691-
return new neo4j.DateTime(neo4j.int(year), neo4j.int(month), neo4j.int(day),
691+
return new neo4j.types.DateTime(neo4j.int(year), neo4j.int(month), neo4j.int(day),
692692
neo4j.int(hour), neo4j.int(minute), neo4j.int(second), neo4j.int(nanosecond), null, zoneId);
693693
}
694694

types/v1/index.d.ts

+17
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,19 @@ declare const integer: {
8383
inSafeRange: typeof inSafeRange;
8484
};
8585

86+
declare const spatial: {
87+
isPoint: typeof isPoint;
88+
};
89+
90+
declare const temporal: {
91+
isDuration: typeof isDuration;
92+
isLocalTime: typeof isLocalTime;
93+
isTime: typeof isTime;
94+
isDate: typeof isDate;
95+
isLocalDateTime: typeof isLocalDateTime;
96+
isDateTime: typeof isDateTime;
97+
};
98+
8699
/*
87100
Both default and non-default exports declare all visible types so that they can be used in client code like this:
88101
@@ -101,6 +114,8 @@ declare const forExport: {
101114
types: typeof types;
102115
session: typeof session;
103116
error: typeof error;
117+
spatial: typeof spatial;
118+
temporal: typeof temporal;
104119
Driver: Driver;
105120
AuthToken: AuthToken;
106121
Config: Config;
@@ -152,6 +167,8 @@ export {
152167
types,
153168
session,
154169
error,
170+
spatial,
171+
temporal,
155172
Driver,
156173
AuthToken,
157174
Config,

0 commit comments

Comments
 (0)