Skip to content

Commit 974c3bd

Browse files
committed
Added module exports for temporal types
And use top-level import in temporal tests.
1 parent 158aaca commit 974c3bd

File tree

2 files changed

+76
-31
lines changed

2 files changed

+76
-31
lines changed

src/v1/index.js

Lines changed: 60 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,23 @@ import VERSION from '../version';
2929
import {assertString, isEmptyObjectOrNull} from './internal/util';
3030
import urlUtil from './internal/url-util';
3131
import HttpDriver from './internal/http/http-driver';
32-
import {Point} from './spatial-types';
32+
import {isPoint, Point} from './spatial-types';
33+
import {
34+
CypherDate,
35+
CypherDateTimeWithZoneId,
36+
CypherDateTimeWithZoneOffset,
37+
CypherDuration,
38+
CypherLocalDateTime,
39+
CypherLocalTime,
40+
CypherTime,
41+
isCypherDate,
42+
isCypherDateTimeWithZoneId,
43+
isCypherDateTimeWithZoneOffset,
44+
isCypherDuration,
45+
isCypherLocalDateTime,
46+
isCypherLocalTime,
47+
isCypherTime
48+
} from './temporal-types';
3349

3450
/**
3551
* @property {function(username: string, password: string, realm: ?string)} basic the function to create a
@@ -196,7 +212,7 @@ function driver(url, authToken, config = {}) {
196212
}
197213

198214
/**
199-
* Object containing constructors for all graph types.
215+
* Object containing constructors for all neo4j types.
200216
*/
201217
const types = {
202218
Node,
@@ -207,7 +223,14 @@ const types = {
207223
Result,
208224
ResultSummary,
209225
Record,
210-
Point
226+
Point,
227+
CypherDate,
228+
CypherDateTimeWithZoneId,
229+
CypherDateTimeWithZoneOffset,
230+
CypherDuration,
231+
CypherLocalDateTime,
232+
CypherLocalTime,
233+
CypherTime
211234
};
212235

213236
/**
@@ -248,7 +271,23 @@ const forExport = {
248271
auth,
249272
types,
250273
session,
251-
error
274+
error,
275+
Point,
276+
isPoint,
277+
CypherDate,
278+
CypherDateTimeWithZoneId,
279+
CypherDateTimeWithZoneOffset,
280+
CypherDuration,
281+
CypherLocalDateTime,
282+
CypherLocalTime,
283+
CypherTime,
284+
isCypherDuration,
285+
isCypherLocalTime,
286+
isCypherTime,
287+
isCypherDate,
288+
isCypherLocalDateTime,
289+
isCypherDateTimeWithZoneOffset,
290+
isCypherDateTimeWithZoneId
252291
};
253292

254293
export {
@@ -260,6 +299,22 @@ export {
260299
auth,
261300
types,
262301
session,
263-
error
302+
error,
303+
Point,
304+
isPoint,
305+
CypherDate,
306+
CypherDateTimeWithZoneId,
307+
CypherDateTimeWithZoneOffset,
308+
CypherDuration,
309+
CypherLocalDateTime,
310+
CypherLocalTime,
311+
CypherTime,
312+
isCypherDuration,
313+
isCypherLocalTime,
314+
isCypherTime,
315+
isCypherDate,
316+
isCypherLocalDateTime,
317+
isCypherDateTimeWithZoneOffset,
318+
isCypherDateTimeWithZoneId
264319
};
265320
export default forExport;

test/v1/temporal-types.test.js

Lines changed: 16 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,11 @@
1717
* limitations under the License.
1818
*/
1919

20-
import neo4j from '../../src/v1';
21-
import {int} from '../../src/v1/integer';
20+
import neo4j from '../../src';
2221
import sharedNeo4j from '../internal/shared-neo4j';
2322
import {ServerVersion, VERSION_3_4_0} from '../../src/v1/internal/server-version';
2423
import timesSeries from 'async/timesSeries';
2524
import _ from 'lodash';
26-
import {
27-
CypherDate,
28-
CypherDateTimeWithZoneId,
29-
CypherDateTimeWithZoneOffset,
30-
CypherDuration,
31-
CypherLocalDateTime,
32-
CypherLocalTime,
33-
CypherTime
34-
} from '../../src/v1/temporal-types';
3525

3626
const RANDOM_VALUES_TO_TEST = 2000;
3727
const MAX_NANO_OF_SECOND = 999999999;
@@ -443,40 +433,40 @@ describe('temporal-types', () => {
443433
}
444434

445435
function randomDateTimeWithZoneOffset() {
446-
return new CypherDateTimeWithZoneOffset(
436+
return new neo4j.CypherDateTimeWithZoneOffset(
447437
randomLocalDateTime(),
448438
randomZoneOffsetSeconds()
449439
);
450440
}
451441

452442
function randomDateTimeWithZoneId() {
453-
return new CypherDateTimeWithZoneId(
443+
return new neo4j.CypherDateTimeWithZoneId(
454444
randomLocalDateTime(),
455445
randomZoneId()
456446
);
457447
}
458448

459449
function randomLocalDateTime() {
460-
return new CypherLocalDateTime(randomDate(), randomLocalTime());
450+
return new neo4j.CypherLocalDateTime(randomDate(), randomLocalTime());
461451
}
462452

463453
function randomDate() {
464-
return new CypherDate(
454+
return new neo4j.CypherDate(
465455
randomInt(MIN_YEAR, MAX_YEAR),
466456
randomInt(1, 12),
467457
randomInt(1, 28)
468458
);
469459
}
470460

471461
function randomTime() {
472-
return new CypherTime(
462+
return new neo4j.CypherTime(
473463
randomLocalTime(),
474464
randomZoneOffsetSeconds(),
475465
);
476466
}
477467

478468
function randomLocalTime() {
479-
return new CypherLocalTime(
469+
return new neo4j.CypherLocalTime(
480470
randomInt(0, 23),
481471
randomInt(0, 59),
482472
randomInt(0, 59),
@@ -485,7 +475,7 @@ describe('temporal-types', () => {
485475
}
486476

487477
function randomZoneOffsetSeconds() {
488-
const randomOffsetWithSeconds = int(randomInt(MIN_TIME_ZONE_OFFSET, MAX_TIME_ZONE_OFFSET));
478+
const randomOffsetWithSeconds = neo4j.int(randomInt(MIN_TIME_ZONE_OFFSET, MAX_TIME_ZONE_OFFSET));
489479
return randomOffsetWithSeconds.div(SECONDS_PER_MINUTE).multiply(SECONDS_PER_MINUTE); // truncate seconds
490480
}
491481

@@ -494,34 +484,34 @@ describe('temporal-types', () => {
494484
}
495485

496486
function duration(months, days, seconds, nanoseconds) {
497-
return new CypherDuration(int(months), int(days), int(seconds), int(nanoseconds));
487+
return new neo4j.CypherDuration(neo4j.int(months), neo4j.int(days), neo4j.int(seconds), neo4j.int(nanoseconds));
498488
}
499489

500490
function localTime(hour, minute, second, nanosecond) {
501-
return new CypherLocalTime(int(hour), int(minute), int(second), int(nanosecond));
491+
return new neo4j.CypherLocalTime(neo4j.int(hour), neo4j.int(minute), neo4j.int(second), neo4j.int(nanosecond));
502492
}
503493

504494
function time(hour, minute, second, nanosecond, offsetSeconds) {
505-
return new CypherTime(localTime(hour, minute, second, nanosecond), int(offsetSeconds));
495+
return new neo4j.CypherTime(localTime(hour, minute, second, nanosecond), neo4j.int(offsetSeconds));
506496
}
507497

508498
function date(year, month, day) {
509-
return new CypherDate(int(year), int(month), int(day));
499+
return new neo4j.CypherDate(neo4j.int(year), neo4j.int(month), neo4j.int(day));
510500
}
511501

512502
function localDateTime(year, month, day, hour, minute, second, nanosecond) {
513-
return new CypherLocalDateTime(date(year, month, day), localTime(hour, minute, second, nanosecond));
503+
return new neo4j.CypherLocalDateTime(date(year, month, day), localTime(hour, minute, second, nanosecond));
514504
}
515505

516506
function dateTimeWithZoneOffset(year, month, day, hour, minute, second, nanosecond, offsetSeconds) {
517-
return new CypherDateTimeWithZoneOffset(localDateTime(year, month, day, hour, minute, second, nanosecond), int(offsetSeconds));
507+
return new neo4j.CypherDateTimeWithZoneOffset(localDateTime(year, month, day, hour, minute, second, nanosecond), neo4j.int(offsetSeconds));
518508
}
519509

520510
function dateTimeWithZoneId(year, month, day, hour, minute, second, nanosecond, zoneId) {
521-
return new CypherDateTimeWithZoneId(localDateTime(year, month, day, hour, minute, second, nanosecond), zoneId);
511+
return new neo4j.CypherDateTimeWithZoneId(localDateTime(year, month, day, hour, minute, second, nanosecond), zoneId);
522512
}
523513

524514
function randomInt(lower, upper) {
525-
return int(_.random(lower, upper));
515+
return neo4j.int(_.random(lower, upper));
526516
}
527517
});

0 commit comments

Comments
 (0)