Skip to content

Commit 4112688

Browse files
authored
Merge pull request #838 from BillFarber/bug/databasePropertyInUrls
MLE-12173 Fixed a bug where a database property caused a problem when creating a URL path for querying ML.
2 parents b861531 + 53e667b commit 4112688

14 files changed

+77
-106
lines changed

lib/documents.js

Lines changed: 20 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ function probeDocumentsImpl(contentOnly, args) {
266266
}
267267
}
268268

269-
const requestOptions = mlutil.newRequestOptions(this.client.getConnectionParams(), path, '&', 'HEAD');
269+
const requestOptions = mlutil.newRequestOptions(this.client.getConnectionParams(), path, 'HEAD');
270270
mlutil.addTxidHeaders(requestOptions, txid);
271271

272272
var operation = new Operation(
@@ -389,7 +389,7 @@ Documents.prototype.protect = function protectDocument() {
389389
path += '&archivePath=' + encodeURIComponent(archivePath);
390390
}
391391

392-
const requestOptions = mlutil.newRequestOptions(this.client.getConnectionParams(), path, '&', 'POST');
392+
const requestOptions = mlutil.newRequestOptions(this.client.getConnectionParams(), path, 'POST');
393393

394394
var operation = new Operation(
395395
'protect document', this.client, requestOptions, 'empty', 'empty'
@@ -456,7 +456,7 @@ Documents.prototype.wipe = function wipeDocument() {
456456
path += '&temporal-collection=' + encodeURIComponent(tempColl);
457457
path += '&result=wiped';
458458

459-
const requestOptions = mlutil.newRequestOptions(this.client.getConnectionParams(), path, '&', 'DELETE');
459+
const requestOptions = mlutil.newRequestOptions(this.client.getConnectionParams(), path, 'DELETE');
460460

461461
var operation = new Operation(
462462
'wipe document', this.client, requestOptions, 'empty', 'empty'
@@ -522,7 +522,7 @@ Documents.prototype.advanceLsqt = function temporalAdvanceLsqt() {
522522
path += '&lag=' + encodeURIComponent(lag);
523523
}
524524

525-
const requestOptions = mlutil.newRequestOptions(this.client.getConnectionParams(), path, '&', 'POST');
525+
const requestOptions = mlutil.newRequestOptions(this.client.getConnectionParams(), path, 'POST');
526526

527527
var operation = new Operation(
528528
'advance LSQT', this.client, requestOptions, 'empty', 'empty'
@@ -707,7 +707,7 @@ function readDocumentsImpl(contentOnly, args) {
707707
categories.indexOf('content') === -1
708708
));
709709

710-
const requestOptions = mlutil.newRequestOptions(this.client.getConnectionParams(), path, '&','GET');
710+
const requestOptions = mlutil.newRequestOptions(this.client.getConnectionParams(), path, 'GET');
711711
if (!isSinglePayload) {
712712
requestOptions.headers = {
713713
Accept: 'multipart/mixed; boundary='+mlutil.multipartBoundary
@@ -842,18 +842,15 @@ function writeStreamImpl(document, categories) {
842842
/*jshint validthis:true */
843843
var endpoint = '/v1/documents';
844844

845-
var sep = '?';
846-
847845
var txid = getTxid(document);
848846

849847
var writeParams = addWriteParams(document, categories, txid);
850848
if (writeParams.length > 0) {
851849
endpoint += writeParams;
852-
sep = '&';
853850
}
854851

855852
var multipartBoundary = mlutil.multipartBoundary;
856-
const requestOptions = mlutil.newRequestOptions(this.client.getConnectionParams(), endpoint, sep, 'POST');
853+
const requestOptions = mlutil.newRequestOptions(this.client.getConnectionParams(), endpoint, 'POST');
857854
requestOptions.headers = {
858855
'Content-Type': 'multipart/mixed; boundary='+multipartBoundary,
859856
'Accept': 'application/json'
@@ -1069,7 +1066,7 @@ function writeMetadata(document, categories) {
10691066
'Content-Type': 'application/json'
10701067
};
10711068

1072-
const requestOptions = mlutil.newRequestOptions(this.client.getConnectionParams(), endpoint, '&', 'PUT');
1069+
const requestOptions = mlutil.newRequestOptions(this.client.getConnectionParams(), endpoint, 'PUT');
10731070
requestOptions.headers = requestHeaders;
10741071
mlutil.addTxidHeaders(requestOptions, txid);
10751072

@@ -1189,7 +1186,7 @@ function writeContent(contentOnly, document, requestParams, categories, requestT
11891186
if (sep === '?') { sep = '&'; }
11901187
}
11911188

1192-
const requestOptions = mlutil.newRequestOptions(this.client.getConnectionParams(), endpoint, sep, hasUri ? 'PUT' : 'POST');
1189+
const requestOptions = mlutil.newRequestOptions(this.client.getConnectionParams(), endpoint, hasUri ? 'PUT' : 'POST');
11931190
requestOptions.headers = requestHeaders;
11941191
mlutil.addTxidHeaders(requestOptions, txid);
11951192
var operation = new Operation(
@@ -1223,10 +1220,8 @@ function writeDocumentList(contentOnly, documents, requestParams, categories) {
12231220
var txid = getTxid(requestParams);
12241221

12251222
var writeParams = addWriteParams(requestParams, categories, txid);
1226-
var sep = '?';
12271223
if (writeParams.length > 0) {
12281224
endpoint += writeParams;
1229-
sep = '&';
12301225
}
12311226

12321227
var multipartBoundary = mlutil.multipartBoundary;
@@ -1236,7 +1231,7 @@ function writeDocumentList(contentOnly, documents, requestParams, categories) {
12361231
'Content-Type': 'multipart/mixed; boundary='+multipartBoundary
12371232
};
12381233

1239-
const requestOptions = mlutil.newRequestOptions(this.client.getConnectionParams(), endpoint, sep, 'POST');
1234+
const requestOptions = mlutil.newRequestOptions(this.client.getConnectionParams(), endpoint, 'POST');
12401235
requestOptions.headers = requestHeaders;
12411236
mlutil.addTxidHeaders(requestOptions, txid);
12421237

@@ -1579,7 +1574,7 @@ function removeDocumentImpl(contentOnly, args) {
15791574
}
15801575
}
15811576

1582-
const requestOptions = mlutil.newRequestOptions(this.client.getConnectionParams(), path, '&','DELETE');
1577+
const requestOptions = mlutil.newRequestOptions(this.client.getConnectionParams(), path, 'DELETE');
15831578
if (versionId != null) {
15841579
requestOptions.headers = {
15851580
'If-Match': versionId
@@ -1692,7 +1687,7 @@ function removeAllDocumentsImpl(contentOnly, params) {
16921687
}
16931688
}
16941689

1695-
const requestOptions = mlutil.newRequestOptions(this.client.getConnectionParams(), endpoint, sep, 'DELETE');
1690+
const requestOptions = mlutil.newRequestOptions(this.client.getConnectionParams(), endpoint, 'DELETE');
16961691
mlutil.addTxidHeaders(requestOptions, txid);
16971692

16981693
var operation = new Operation(
@@ -1871,7 +1866,7 @@ function queryDocumentsImpl(collectionParam, contentOnly, builtQuery, timestamp,
18711866
}
18721867
}
18731868

1874-
const requestOptions = mlutil.newRequestOptions(this.client.getConnectionParams(), endpoint, '&', 'POST');
1869+
const requestOptions = mlutil.newRequestOptions(this.client.getConnectionParams(), endpoint, 'POST');
18751870
requestOptions.headers = {
18761871
'Content-Type': (isMultipart ?
18771872
'multipart/mixed; boundary='+multipartBoundary :
@@ -2068,7 +2063,7 @@ Documents.prototype.patch = function patchDocuments() {
20682063
patchBody.pathlang = pathlang;
20692064
}
20702065

2071-
const requestOptions = mlutil.newRequestOptions(this.client.getConnectionParams(), endpoint, '&', 'POST');
2066+
const requestOptions = mlutil.newRequestOptions(this.client.getConnectionParams(), endpoint, 'POST');
20722067
requestOptions.headers = {
20732068
'Content-Type':
20742069
((format === 'xml') ? 'application/xml' : 'application/json'),
@@ -2194,7 +2189,7 @@ Documents.prototype.suggest = function suggestDocuments() {
21942189
endpoint += '&limit=' + limit;
21952190
}
21962191

2197-
const requestOptions = mlutil.newRequestOptions(this.client.getConnectionParams(), endpoint, '&', 'POST');
2192+
const requestOptions = mlutil.newRequestOptions(this.client.getConnectionParams(), endpoint, 'POST');
21982193
requestOptions.headers = {
21992194
'Content-Type': 'application/json',
22002195
'Accept': 'application/json',
@@ -2242,7 +2237,7 @@ function writeAllDocumentsImpl(inputStream,jobOptions) {
22422237

22432238
let path = '/v1/internal/forestinfo';
22442239
let connectionParams = this.client.getConnectionParams();
2245-
const requestOptions = mlutil.newRequestOptions(connectionParams, path, '&','GET');
2240+
const requestOptions = mlutil.newRequestOptions(connectionParams, path, 'GET');
22462241

22472242
requestOptions.headers = {
22482243
'Accept': 'application/json',
@@ -2493,7 +2488,7 @@ function queryAllDocumentsImpl(query, jobOptions) {
24932488
}
24942489

24952490
let path = '/v1/internal/forestinfo';
2496-
const requestOptions = mlutil.newRequestOptions(this.client.getConnectionParams(), path, '&', 'POST');
2491+
const requestOptions = mlutil.newRequestOptions(this.client.getConnectionParams(), path, 'POST');
24972492
let wrapper = {ctsast: bldrbase.exportArg(query.whereClause)};
24982493

24992494
requestOptions.headers = {
@@ -2755,7 +2750,7 @@ Documents.prototype.readAll = function readAllDocuments(stream, options) {
27552750
function readAllDocumentsImpl(inputStream, jobOptions) {
27562751

27572752
let path = '/v1/internal/forestinfo';
2758-
const requestOptions = mlutil.newRequestOptions(this.client.getConnectionParams(), path, '&', 'GET');
2753+
const requestOptions = mlutil.newRequestOptions(this.client.getConnectionParams(), path, 'GET');
27592754

27602755
requestOptions.headers = {
27612756
'Accept': 'application/json',
@@ -3335,7 +3330,7 @@ Documents.prototype.transformAll = function transformAllDocuments(stream, option
33353330

33363331
function transformAllDocumentsImpl(inputStream, jobOptions){
33373332
let path = '/v1/internal/forestinfo';
3338-
const requestOptions = mlutil.newRequestOptions(this.client.getConnectionParams(), path, '&', 'GET');
3333+
const requestOptions = mlutil.newRequestOptions(this.client.getConnectionParams(), path, 'GET');
33393334

33403335
requestOptions.headers = {
33413336
'Accept': 'application/json',
@@ -3439,7 +3434,7 @@ function onTransformAllInit(output) {
34393434

34403435
jobState.endpoint = endpoint;
34413436

3442-
const requestOptions = mlutil.newRequestOptions(jobState.docInstance.client.getConnectionParams(), jobState.endpoint, '&', 'POST');
3437+
const requestOptions = mlutil.newRequestOptions(jobState.docInstance.client.getConnectionParams(), jobState.endpoint, 'POST');
34433438
requestOptions.headers = {
34443439
'Accept': 'text/uri-list',
34453440
'Content-Type': 'text/uri-list'
@@ -3747,7 +3742,7 @@ Documents.prototype.removeAllUris = function removeAllUrisDocuments(stream, opti
37473742

37483743
function removeAllUrisDocumentsImpl(inputStream, jobOptions){
37493744
let path = '/v1/internal/forestinfo';
3750-
const requestOptions = mlutil.newRequestOptions(this.client.getConnectionParams(), path, '&', 'GET');
3745+
const requestOptions = mlutil.newRequestOptions(this.client.getConnectionParams(), path, 'GET');
37513746

37523747
requestOptions.headers = {
37533748
'Accept': 'application/json',

lib/endpoint-proxy.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ function emptyRequest(client, funcdef, args) {
3333
}
3434

3535
const outputTransform = specifyOutputTransform(funcdef, requestHeaders);
36-
const requestOptions = mlutil.newRequestOptions(client.getConnectionParams(), endpoint, '?', 'POST');
36+
const requestOptions = mlutil.newRequestOptions(client.getConnectionParams(), endpoint, 'POST');
3737
requestOptions.headers = requestHeaders;
3838

3939
const operation = new Operation(
@@ -52,7 +52,7 @@ function multiAtomicRequest(client, funcdef, args) {
5252

5353
checkArgNames(funcdef, args, requestHeaders);
5454

55-
const requestOptions = mlutil.newRequestOptions(client.getConnectionParams(), endpoint, '?', 'POST');
55+
const requestOptions = mlutil.newRequestOptions(client.getConnectionParams(), endpoint, 'POST');
5656
requestOptions.headers = requestHeaders;
5757

5858
const operation = new Operation(
@@ -92,7 +92,7 @@ function multiNodeRequest(client, funcdef, args) {
9292

9393
checkArgNames(funcdef, args, requestHeaders);
9494

95-
const requestOptions = mlutil.newRequestOptions(client.getConnectionParams(), endpoint, '?', 'POST');
95+
const requestOptions = mlutil.newRequestOptions(client.getConnectionParams(), endpoint, 'POST');
9696
requestOptions.headers = requestHeaders;
9797

9898
const operation = new Operation(

lib/graphs.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ Graphs.prototype.read = function readGraph() {
181181
}
182182
}
183183

184-
const requestOptions = mlutil.newRequestOptions(this.client.getConnectionParams(), endpoint, '&', 'GET');
184+
const requestOptions = mlutil.newRequestOptions(this.client.getConnectionParams(), endpoint, 'GET');
185185
requestOptions.headers = {
186186
'Accept': contentType
187187
};
@@ -373,7 +373,7 @@ function changeGraph(action, isStreaming, args) {
373373
if (sep === '?') { sep = '&'; }
374374
}
375375

376-
const requestOptions = mlutil.newRequestOptions(this.client.getConnectionParams(), endpoint, sep, ((action === 'write') ? 'PUT' : 'POST'));
376+
const requestOptions = mlutil.newRequestOptions(this.client.getConnectionParams(), endpoint, ((action === 'write') ? 'PUT' : 'POST'));
377377
requestOptions.headers = {
378378
'Content-Type': contentType
379379
};
@@ -477,7 +477,7 @@ function applyGraph(action, args) {
477477
if (sep === '?') { sep = '&'; }
478478
}
479479

480-
const requestOptions = mlutil.newRequestOptions(this.client.getConnectionParams(), endpoint, sep, ((action === 'remove') ? 'DELETE' : 'HEAD'));
480+
const requestOptions = mlutil.newRequestOptions(this.client.getConnectionParams(), endpoint, ((action === 'remove') ? 'DELETE' : 'HEAD'));
481481

482482
var operation = new Operation(
483483
action+' graph', this.client, requestOptions, 'empty', 'empty'
@@ -561,7 +561,7 @@ Graphs.prototype.list = function listGraphs() {
561561
}
562562
}
563563

564-
const requestOptions = mlutil.newRequestOptions(this.client.getConnectionParams(), endpoint, sep, 'GET');
564+
const requestOptions = mlutil.newRequestOptions(this.client.getConnectionParams(), endpoint, 'GET');
565565
if (!noContentType) {
566566
requestOptions.headers = {
567567
'Accept': contentType
@@ -752,7 +752,7 @@ Graphs.prototype.sparql = function queryGraphSPARQL() {
752752
queryBody.search.sparql = query;
753753
}
754754

755-
const requestOptions = mlutil.newRequestOptions(this.client.getConnectionParams(), endpoint, sep, 'POST');
755+
const requestOptions = mlutil.newRequestOptions(this.client.getConnectionParams(), endpoint, 'POST');
756756
requestOptions.headers = {
757757
'Content-Type': contentType,
758758
'Accept': acceptType
@@ -878,7 +878,7 @@ Graphs.prototype.sparqlUpdate = function updateGraphSPARQL() {
878878
if (sep === '?') { sep = '&'; }
879879
}
880880

881-
const requestOptions = mlutil.newRequestOptions(this.client.getConnectionParams(), endpoint, sep, 'POST');
881+
const requestOptions = mlutil.newRequestOptions(this.client.getConnectionParams(), endpoint, 'POST');
882882
requestOptions.headers = {
883883
'Content-Type': 'application/sparql-update'
884884
};

lib/internal.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class InternalClass {
2626
if(!path){
2727
throw new Error('Path is needed to send request.');
2828
}
29-
let requestOptions = mlutil.newRequestOptions(this.clientObject.getConnectionParams(), path, '?');
29+
let requestOptions = mlutil.newRequestOptions(this.clientObject.getConnectionParams(), path);
3030
if (requestOptionsCallback) {
3131
requestOptionsCallback(requestOptions);
3232
}

lib/marklogic.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,7 @@ MarkLogicClient.prototype.getConnectionParams = function getConnectionParams() {
392392
* it contains httpStatusCode and httpStatusMessage properties identifying the failure.
393393
*/
394394
MarkLogicClient.prototype.checkConnection = function checkConnection() {
395-
const requestOptions = mlutil.newRequestOptions(this.connectionParams, '/v1/ping', '?', 'HEAD');
395+
const requestOptions = mlutil.newRequestOptions(this.connectionParams, '/v1/ping', 'HEAD');
396396
var operation = new Operation(
397397
'test operation', this, requestOptions, 'empty', 'empty'
398398
);

lib/mlutil.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ function endpointTransform(transform) {
152152
}
153153
}
154154

155-
function newRequestOptions(connectionParams, endpoint, separator, method) {
155+
function newRequestOptions(connectionParams, endpoint, method) {
156156
const requestOptions = copyProperties(connectionParams);
157157
let database = connectionParams.database;
158158
if(connectionParams.basePath) {
@@ -163,7 +163,17 @@ function newRequestOptions(connectionParams, endpoint, separator, method) {
163163
}
164164
requestOptions.method = method? method:'GET';
165165

166-
requestOptions.path = (database == null)? endpoint: (endpoint + separator + 'database=' + encodeURIComponent(database));
166+
if (database !== null) {
167+
if (endpoint.includes('?')) {
168+
if (endpoint.endsWith('?')) {
169+
requestOptions.path = (database == null) ? endpoint : (endpoint + 'database=' + encodeURIComponent(database));
170+
} else {
171+
requestOptions.path = (database == null) ? endpoint : (endpoint + '&database=' + encodeURIComponent(database));
172+
}
173+
} else {
174+
requestOptions.path = (database == null) ? endpoint : (endpoint + '?database=' + encodeURIComponent(database));
175+
}
176+
}
167177
return requestOptions;
168178
}
169179

lib/resources-exec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ function makeRequestOptions(client, args) {
8181
}
8282
}
8383

84-
const requestOptions = mlutil.newRequestOptions(client.getConnectionParams(), path, sep);
84+
const requestOptions = mlutil.newRequestOptions(client.getConnectionParams(), path);
8585
mlutil.addTxidHeaders(requestOptions, txid);
8686

8787
return requestOptions;

lib/rows.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ function queryRowsOperationImpl(self, builtPlan, streamType, options, bindingArg
179179
const query = JSON.stringify(builtPlan.export());
180180
const multipartBoundary = mlutil.multipartBoundary;
181181
const endpoint = '/v1/rows';
182-
const requestOptions = mlutil.newRequestOptions(connectionParams, endpoint, '?', 'POST');
182+
const requestOptions = mlutil.newRequestOptions(connectionParams, endpoint, 'POST');
183183

184184
requestOptions.headers = {
185185
'Content-Type': 'multipart/form-data; boundary=' + multipartBoundary,
@@ -242,7 +242,7 @@ function queryRowsOperationImpl(self, builtPlan, streamType, options, bindingArg
242242
endpoint += (complexValues === 'reference') ? sep + 'node-columns=reference' : '';
243243
break;
244244
}
245-
let requestOptions = mlutil.newRequestOptions(connectionParams, endpoint, '&', 'POST');
245+
let requestOptions = mlutil.newRequestOptions(connectionParams, endpoint, 'POST');
246246
requestOptions.headers = {
247247
'Content-Type': contentTypeHeader,
248248
'Accept': acceptHeader
@@ -410,7 +410,7 @@ Rows.prototype.generateView = function generateViewRows(builtPlan, schema, view,
410410

411411
const contentTypeHeader = queryContentType(builtPlan, queryType);
412412
const endpoint = '/v1/rows?output=generateView&schemaName='+schema+'&viewName='+view;
413-
const requestOptions = mlutil.newRequestOptions(this.client.getConnectionParams(), endpoint, '&', 'POST');
413+
const requestOptions = mlutil.newRequestOptions(this.client.getConnectionParams(), endpoint, 'POST');
414414

415415
requestOptions.headers = {
416416
'Content-Type': contentTypeHeader,
@@ -468,7 +468,7 @@ Rows.prototype.generateView = function generateViewRows(builtPlan, schema, view,
468468
Rows.prototype.queryAll = function queryAllDocumentsImpl(batchView, jobOptions){
469469

470470
let path = '/v1/internal/viewinfo';
471-
const requestOptions = mlutil.newRequestOptions(this.client.getConnectionParams(), path, '&', 'POST');
471+
const requestOptions = mlutil.newRequestOptions(this.client.getConnectionParams(), path, 'POST');
472472

473473
requestOptions.headers = {
474474
'Accept': 'application/json',

lib/server-exec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ function serverExec(execName, args) {
285285
sep = '&';
286286
}
287287

288-
const requestOptions = mlutil.newRequestOptions(client.getConnectionParams(), endpoint, sep, 'POST');
288+
const requestOptions = mlutil.newRequestOptions(client.getConnectionParams(), endpoint, 'POST');
289289
requestOptions.headers = {
290290
'Content-Type': 'application/x-www-form-urlencoded',
291291
'Accept': 'multipart/mixed; boundary='+mlutil.multipartBoundary

0 commit comments

Comments
 (0)