Skip to content

Commit d9c5445

Browse files
committed
jsdoc for bitemporal, some geospatial
1 parent b812355 commit d9c5445

File tree

3 files changed

+214
-10
lines changed

3 files changed

+214
-10
lines changed

lib/documents.js

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,13 @@ function createWriteStream(document) {
390390
* the {@link transforms#write} function.
391391
* @param {string} [forestName] - the name of a forest in which to write
392392
* the documents.
393+
* @param {string} [temporalCollection] - the name of the temporal collection;
394+
* use only when writing temporal documents that have the JSON properties or XML elements
395+
* specifying the valid and system start and end times as defined by the valid and
396+
* system axis for the temporal collection
397+
* @param {string|Date} [systemTime] - a datetime to use as the system start time
398+
* instead of the current time of the database server; can only be supplied
399+
* if the temporalCollection parameter is also supplied
393400
* @returns {ResultProvider} an object whose result() function takes
394401
* a {@link documents#writeResult} success callback.
395402
*/
@@ -448,11 +455,12 @@ function writeDocumentsImpl(contentOnly, args) {
448455
if (!valcheck.isNullOrUndefined(temporalCollection)) {
449456
endpoint += sep+'temporal-collection='+temporalCollection;
450457
if (sep !== '&') { sep = '&'; }
451-
}
452-
var systemTime = requestParams.systemTime;
453-
if (!valcheck.isNullOrUndefined(systemTime)) {
454-
endpoint += sep+'system-time='+systemTime;
455-
if (sep !== '&') { sep = '&'; }
458+
var systemTime = requestParams.systemTime;
459+
if (valcheck.isString(systemTime)) {
460+
path += '&system-time='+systemTime;
461+
} else if (valcheck.isDate(systemTime)) {
462+
path += '&system-time='+systemTime.toISOString();
463+
}
456464
}
457465
}
458466

@@ -653,6 +661,12 @@ function removeOutputTransform(headers, data) {
653661
* @method documents#remove
654662
* @param {string} uri - the uri for the database document
655663
* @param {string} [txid] - the transaction id for an open transaction
664+
* @param {string} [temporalCollection] - the name of the temporal collection;
665+
* use only when deleting a document created as a temporal document; sets the
666+
* system end time to record when the document was no longer active
667+
* @param {string|Date} [systemTime] - a datetime to use as the system end time
668+
* instead of the current time of the database server; can only be supplied
669+
* if the temporalCollection parameter is also supplied
656670
* @returns {ResultProvider} an object whose result() function takes
657671
* a {@link documents#removeResult} success callback.
658672
*/
@@ -692,9 +706,11 @@ function removeDocumentImpl(contentOnly, args) {
692706
}
693707
if (!valcheck.isNullOrUndefined(temporalCollection)) {
694708
path += '&temporal-collection='+temporalCollection;
695-
}
696-
if (!valcheck.isNullOrUndefined(systemTime)) {
697-
path += '&system-time='+systemTime;
709+
if (valcheck.isString(systemTime)) {
710+
path += '&system-time='+systemTime;
711+
} else if (valcheck.isDate(systemTime)) {
712+
path += '&system-time='+systemTime.toISOString();
713+
}
698714
}
699715

700716
var connectionParams = this.client.connectionParams;

lib/query-builder.js

Lines changed: 180 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,18 @@ function addIndex(query, index, isContainer) {
8383
* or path index.
8484
* @typedef {object} queryBuilder.IndexedName
8585
*/
86+
/**
87+
* The specification of a point or an area (such as a box, circle, or polygon)
88+
* for use as criteria in a geospatial query.
89+
* @typedef {object} queryBuilder.Region
90+
*/
91+
/**
92+
* The specification of the latitude and longitude
93+
* returned by the {@link queryBuilder#latlon} function
94+
* for a coordinate of a {@link queryBuilder.Region}.
95+
* @typedef {object} queryBuilder.LatLon
96+
*/
97+
8698

8799
/**
88100
* Builds a query for the intersection of the subqueries.
@@ -217,6 +229,19 @@ function boost() {
217229
}};
218230
}
219231
}
232+
/**
233+
* Specifies a rectangular region with the coordinates of the corners.
234+
* The coordinates can either be specified either by passing the return value
235+
* from the {@link queryBuilder#southWestNorthEast} function or as a list
236+
* of points in South, West, North, and East order.
237+
* @method
238+
* @memberof queryBuilder#
239+
* @param {queryBuilder.LatLon} south - the south coordinate of the box
240+
* @param {queryBuilder.LatLon} west - the west coordinate for the box
241+
* @param {queryBuilder.LatLon} north - the north coordinate for the box
242+
* @param {queryBuilder.LatLon} east - the east coordinate for the box
243+
* @returns {queryBuilder.Region} the region criteria for a geospatial query
244+
*/
220245
function box() {
221246
var args = mlutil.asArray.apply(null, arguments);
222247
var region = null;
@@ -245,6 +270,17 @@ function box() {
245270
}
246271
return {box: region};
247272
}
273+
/**
274+
* Specifies a circular region based on a radius and the coordinate of the center.
275+
* The coordinate can either be specified by passing the return value from
276+
* the {@link queryBuilder#latlon} function or by passing the latitude and longitude
277+
* numbers in that order (possibly wrapped in an array).
278+
* @method
279+
* @memberof queryBuilder#
280+
* @param {number} radius - the radius for the circle
281+
* @param {queryBuilder.LatLon} center - the center for the circle
282+
* @returns {queryBuilder.Region} the region criteria for a geospatial query
283+
*/
248284
function circle() {
249285
var args = mlutil.asArray.apply(null, arguments);
250286
var query = {};
@@ -333,6 +369,25 @@ function collection() {
333369
uri: args
334370
}};
335371
}
372+
/**
373+
* Builds a query matching temporal documents with a system start time
374+
* prior to the LSQT (Latest System Query Time). Advancing the LSQT can be
375+
* done manually or on an automated basis to include more recent
376+
* temporal documents in the result set.
377+
* @method
378+
* @memberof queryBuilder#
379+
* @param {string} temporalCollection - the name of the temporal collection
380+
* that retains the temporal documents
381+
* @param {queryBuilder.WeightParam} [weight] - a weight returned
382+
* by {@link queryBuilder#weight} to increase or decrease the score
383+
* of subqueries relative to other queries in the complete search
384+
* @param {string|Date} [timestamp] - a datetime older than the LSQT
385+
* to use as the upper boundary for an older view of the database
386+
* @param {queryBuilder.TemporalOptionsParam} [temporalOptions] - a list
387+
* of options returned by {@link queryBuilder#temporalOptions} to modify
388+
* the temporal query
389+
* @returns {queryBuilder.Query} a composable query
390+
*/
336391
function lsqtQuery() {
337392
var args = mlutil.asArray.apply(null, arguments);
338393
var argLen = args.length;
@@ -589,7 +644,21 @@ function fragmentScope() {
589644
}
590645
throw new Error('unknown argument: '+scope);
591646
}
592-
// TODO: jsdoc for geospatial
647+
648+
/**
649+
* Builds a query for a geospatial location represented by an XML attribute pair
650+
* that matches the {queryBuilder.Region} criteria.
651+
* The coordinates can either be specified either by passing the return value
652+
* from the {@link queryBuilder#southWestNorthEast} function or as a list
653+
* of points in South, West, North, and East order.
654+
* @method
655+
* @memberof queryBuilder#
656+
* @param {string|string[]|queryBuilder.BindingParam} collections - either
657+
* one or more collection uris to match or exactly one binding (returned
658+
* by the {@link queryBuilder#bind} function) for parsing the collection
659+
* uris from a query string; required except for values queries
660+
* @returns {queryBuilder.Query} a composable query
661+
*/
593662
function geoAttributePair() {
594663
var args = mlutil.asArray.apply(null, arguments);
595664
if (args.length < 3) {
@@ -877,6 +946,16 @@ function heatmap() {
877946
function geoOptions() {
878947
return {'geo-option': mlutil.asArray.apply(null, arguments)};
879948
}
949+
/**
950+
* Specifies the latitude and longitude for a coordinate of the region
951+
* criteria for a geospatial query. The latitude and longitude can be
952+
* passed as individual numeric parameters or wrapped in an array
953+
* @method
954+
* @memberof queryBuilder#
955+
* @param {number} latitude - the north-south location
956+
* @param {number} longitude - the east-west location
957+
* @returns {queryBuilder.LatLon} a coordinate for a {queryBuilder.Region}
958+
*/
880959
function latlon() {
881960
var args = mlutil.asArray.apply(null, arguments);
882961
if (args.length !== 2)
@@ -1030,6 +1109,15 @@ function pathIndex() {
10301109
}
10311110
return {'path-index': query};
10321111
}
1112+
/**
1113+
* Specifies a point region either by passing the return value from
1114+
* the {@link queryBuilder#latlon} function or by passing the latitude and longitude
1115+
* numbers in that order (possibly wrapped in an array).
1116+
* @method
1117+
* @memberof queryBuilder#
1118+
* @param {queryBuilder.LatLon} coordinate - the point location
1119+
* @returns {queryBuilder.Region} the region criteria for a geospatial query
1120+
*/
10331121
function point() {
10341122
var args = mlutil.asArray.apply(null, arguments);
10351123
var region = null;
@@ -1052,6 +1140,16 @@ function point() {
10521140
}
10531141
return {point: [region]};
10541142
}
1143+
/**
1144+
* Specifies a polygon region as a list of coordinate parameters or as a coordinate array
1145+
* where each coordinate is specified either by the return value from
1146+
* the {@link queryBuilder#latlon} function or by wrapping the latitude and
1147+
* longitude numbers in an array.
1148+
* @method
1149+
* @memberof queryBuilder#
1150+
* @param {...queryBuilder.LatLon} coordinate - the polygon coordinates
1151+
* @returns {queryBuilder.Region} the region criteria for a geospatial query
1152+
*/
10551153
function polygon() {
10561154
var args = mlutil.asArray.apply(null, arguments);
10571155
var points = [];
@@ -1124,6 +1222,24 @@ function nsName() {
11241222
throw new Error('too many arguments: '+args.length);
11251223
}
11261224
}
1225+
/**
1226+
* The specification for a timespan or timestamp for an query
1227+
* returned by the {@link queryBuilder#period} function.
1228+
* @typedef {object} queryBuilder.PeriodParam
1229+
*/
1230+
/**
1231+
* Specifies a timespan or timestamp for comparison with
1232+
* a valid or system timespan in temporal documents in
1233+
* a {@link queryBuilder#periodRange} temporal query.
1234+
* @method
1235+
* @memberof queryBuilder#
1236+
* @param {string|Date} startTimestamp - the starting datetime for a timespan
1237+
* or the datetime for a timestamp
1238+
* @param {string|Date} [endTimestamp] - the starting datetime for a timespan
1239+
* or the datetime for a timestamp
1240+
* @returns {queryBuilder.PeriodParam} the specification of a period
1241+
* for a {@link queryBuilder#periodRange} temporal query
1242+
*/
11271243
function period() {
11281244
var startDate = null;
11291245
var endDate = null;
@@ -1162,6 +1278,24 @@ function period() {
11621278

11631279
return periodVal;
11641280
}
1281+
/**
1282+
* Builds a query matching temporal documents based on the relationship
1283+
* between the valid period and the system period. For instance, this
1284+
* query can find cases where what was believed to be true (the valid time)
1285+
* was recorded (the system time) only afterward (the valid axis is before
1286+
* the system axis).
1287+
* @method
1288+
* @memberof queryBuilder#
1289+
* @param {string} axis1 - the configured name of the valid or system axis
1290+
* @param {string} operator - the name of an Allen interval operator or
1291+
* ISO SQL 2011 period operator
1292+
* @param {string} axis2 - the configured name of the valid or system axis, which
1293+
* must be different from axis1
1294+
* @param {queryBuilder.TemporalOptionsParam} [temporalOptions] - a list
1295+
* of options returned by {@link queryBuilder#temporalOptions} to modify
1296+
* the temporal query
1297+
* @returns {queryBuilder.Query} a composable query
1298+
*/
11651299
function periodCompare() {
11661300
var argLen = arguments.length;
11671301

@@ -1194,6 +1328,25 @@ function periodCompare() {
11941328

11951329
return {'period-compare-query': query};
11961330
}
1331+
/**
1332+
* Builds a query matching temporal documents based on the relationship
1333+
* between the valid or system period and the specified period.
1334+
* This query can find what was believed to be true (the valid time)
1335+
* or was recorded (the system time) during a timespan or before or
1336+
* after a time.
1337+
* @method
1338+
* @memberof queryBuilder#
1339+
* @param {string} axis - the configured name of the valid or system axis
1340+
* @param {string} operator - the name of an Allen interval operator or
1341+
* ISO SQL 2011 period operator
1342+
* @param {queryBuilder.PeriodParam} [period] - a timespan or timestamp
1343+
* returned by {@link queryBuilder#period} to compare with the valid or
1344+
* system time of temporal documents
1345+
* @param {queryBuilder.TemporalOptionsParam} [temporalOptions] - a list
1346+
* of options returned by {@link queryBuilder#temporalOptions} to modify
1347+
* the temporal query
1348+
* @returns {queryBuilder.Query} a composable query
1349+
*/
11971350
function periodRange() {
11981351
var argLen = arguments.length;
11991352

@@ -1233,6 +1386,20 @@ function periodRange() {
12331386

12341387
return {'period-range-query': query};
12351388
}
1389+
/**
1390+
* Options for an query returned by the {@link queryBuilder#temporalOptions}
1391+
* function.
1392+
* @typedef {object} queryBuilder.TemporalOptionsParam
1393+
*/
1394+
/**
1395+
* Provides options modifying the default behavior
1396+
* of an {@link queryBuilder#lsqtQuery}, {@link queryBuilder#periodCompare},
1397+
* or {@link queryBuilder#periodRange} query.
1398+
* @method
1399+
* @memberof queryBuilder#
1400+
* @param {...string} options - options supported for temporal queries
1401+
* @returns {queryBuilder.TemporalOptionsParam} options for the temporal query
1402+
*/
12361403
function temporalOptions() {
12371404
return {'temporal-option': mlutil.asArray.apply(null, arguments)};
12381405
}
@@ -1376,6 +1543,17 @@ function range() {
13761543
function rangeOptions() {
13771544
return {'range-option': mlutil.asArray.apply(null, arguments)};
13781545
}
1546+
/**
1547+
* A convenience for specifying the coordinates of a box as a list of parameters.
1548+
* @method
1549+
* @memberof queryBuilder#
1550+
* @param {queryBuilder.LatLon} south - the south coordinate
1551+
* @param {queryBuilder.LatLon} west - the west coordinate
1552+
* @param {queryBuilder.LatLon} north - the north coordinate
1553+
* @param {queryBuilder.LatLon} east - the east coordinate
1554+
* @returns {object} the coordinates for passing to
1555+
* the {@link queryBuilder#box} function to specify a region
1556+
*/
13791557
function southWestNorthEast() {
13801558
var args = mlutil.asArray.apply(null, arguments);
13811559
if (args.length !== 4) {
@@ -1881,7 +2059,7 @@ function transform(name, params) {
18812059
return {'document-transform': transformList};
18822060
}
18832061

1884-
// TODO: jsDoc for snippet
2062+
// TODO: jsDoc for snippet, extract, transform
18852063
/**
18862064
* Sets the slice clause of a built query to select a slice of documents
18872065
* from the result set based on the start document within the result set

lib/values-builder.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,14 @@ var qb = require('./query-builder.js');
7171
* @borrows queryBuilder#heatmap as valuesBuilder#heatmap
7272
* @borrows queryBuilder#latlon as valuesBuilder#latlon
7373
* @borrows queryBuilder#locksFragment as valuesBuilder#locksFragment
74+
* @borrows queryBuilder#lsqtQuery as valuesBuilder#lsqtQuery
7475
* @borrows queryBuilder#near as valuesBuilder#near
7576
* @borrows queryBuilder#not as valuesBuilder#not
7677
* @borrows queryBuilder#notIn as valuesBuilder#notIn
7778
* @borrows queryBuilder#pathIndex as valuesBuilder#pathIndex
79+
* @borrows queryBuilder#period as valuesBuilder#period
80+
* @borrows queryBuilder#periodCompare as valuesBuilder#periodCompare
81+
* @borrows queryBuilder#periodRange as valuesBuilder#periodRange
7882
* @borrows queryBuilder#point as valuesBuilder#point
7983
* @borrows queryBuilder#polygon as valuesBuilder#polygon
8084
* @borrows queryBuilder#properties as valuesBuilder#properties
@@ -86,6 +90,7 @@ var qb = require('./query-builder.js');
8690
* @borrows queryBuilder#rangeOptions as valuesBuilder#rangeOptions
8791
* @borrows queryBuilder#scope as valuesBuilder#scope
8892
* @borrows queryBuilder#southWestNorthEast as valuesBuilder#southWestNorthEast
93+
* @borrows queryBuilder#temporalOptions as valuesBuilder#temporalOptions
8994
* @borrows queryBuilder#term as valuesBuilder#term
9095
* @borrows queryBuilder#termOptions as valuesBuilder#termOptions
9196
* @borrows queryBuilder#transform as valuesBuilder#transform
@@ -390,10 +395,14 @@ module.exports = {
390395
heatmap: qb.heatmap,
391396
latlon: qb.latlon,
392397
locksFragment: qb.locksFragment,
398+
lsqtQuery: qb.lsqtQuery,
393399
near: qb.near,
394400
not: qb.not,
395401
notIn: qb.notIn,
396402
pathIndex: qb.pathIndex,
403+
period: qb.period,
404+
periodCompare: qb.periodCompare,
405+
periodRange: qb.periodRange,
397406
point: qb.point,
398407
polygon: qb.polygon,
399408
properties: qb.properties,
@@ -405,6 +414,7 @@ module.exports = {
405414
rangeOptions: qb.rangeOptions,
406415
scope: qb.scope,
407416
southWestNorthEast: qb.southWestNorthEast,
417+
temporalOptions: qb.temporalOptions,
408418
term: qb.term,
409419
termOptions: qb.termOptions,
410420
transform: qb.transform,

0 commit comments

Comments
 (0)