Skip to content

Commit

Permalink
Merge pull request #840 from marklogic/develop
Browse files Browse the repository at this point in the history
merge develop 3.3.1 into master
  • Loading branch information
BillFarber authored Feb 2, 2024
2 parents f004f8c + 41cd209 commit f28ce95
Show file tree
Hide file tree
Showing 17 changed files with 87 additions and 111 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# CHANGELOG

## 3.3.1
#### Bug Fix

- Fixed a bug where a database property caused a problem when creating a URL path for querying ML.

## 3.3.0
#### New Functionality

Expand Down
7 changes: 5 additions & 2 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ def runTests(String type,String version){
copyRPM type,version
setUpML '$WORKSPACE/xdmp/src/Mark*.rpm'
sh '''
export JAVA_HOME=/home/builder/java/openjdk-1.8.0-262
export PATH=${NODE_HOME_DIR}/bin:$PATH
export JAVA_HOME=$JAVA_HOME_DIR
export GRADLE_USER_HOME=$WORKSPACE/$GRADLE_DIR
export PATH=$JAVA_HOME/bin:$GRADLE_USER_HOME:${NODE_HOME_DIR}/bin:$PATH
cd node-client-api
node --version
npm --version
Expand Down Expand Up @@ -84,6 +85,8 @@ pipeline{
NODE_HOME_DIR= "/home/builder/nodeJs/node-v18.14.0-linux-x64"
DMC_USER = credentials('MLBUILD_USER')
DMC_PASSWORD = credentials('MLBUILD_PASSWORD')
GRADLE_DIR=".gradle"
JAVA_HOME_DIR="/home/builder/java/openjdk-1.8.0-262"
}
stages{
stage('runtests-11.1.0'){
Expand Down
3 changes: 0 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,8 @@ db.createCollection(
### Resources

* [Node.js Client API Documentation](https://docs.marklogic.com/jsdoc/index.html)
* [Feature Overview of the Node.js Client API](http://developer.marklogic.com/features/node-client-api)
* [The Node.js Client API in 5 Minutes](https://developer.marklogic.com/learn/node-in-5-minutes)
* [Node.js Application Developer's Guide](http://docs.marklogic.com/guide/node-dev)
* [MarkLogic Training for the Node.js Client API](http://www.marklogic.com/training-courses/developing-marklogic-applications-i-node-js/)
* [MarkLogic On-Demand Courses for Node.js](https://mlu.marklogic.com/ondemand/index.xqy?q=Series%3A%22Node.js%22)

### Code Examples

Expand Down
45 changes: 20 additions & 25 deletions lib/documents.js
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ function probeDocumentsImpl(contentOnly, args) {
}
}

const requestOptions = mlutil.newRequestOptions(this.client.getConnectionParams(), path, '&', 'HEAD');
const requestOptions = mlutil.newRequestOptions(this.client.getConnectionParams(), path, 'HEAD');
mlutil.addTxidHeaders(requestOptions, txid);

var operation = new Operation(
Expand Down Expand Up @@ -389,7 +389,7 @@ Documents.prototype.protect = function protectDocument() {
path += '&archivePath=' + encodeURIComponent(archivePath);
}

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

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

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

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

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

var operation = new Operation(
'advance LSQT', this.client, requestOptions, 'empty', 'empty'
Expand Down Expand Up @@ -707,7 +707,7 @@ function readDocumentsImpl(contentOnly, args) {
categories.indexOf('content') === -1
));

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

var sep = '?';

var txid = getTxid(document);

var writeParams = addWriteParams(document, categories, txid);
if (writeParams.length > 0) {
endpoint += writeParams;
sep = '&';
}

var multipartBoundary = mlutil.multipartBoundary;
const requestOptions = mlutil.newRequestOptions(this.client.getConnectionParams(), endpoint, sep, 'POST');
const requestOptions = mlutil.newRequestOptions(this.client.getConnectionParams(), endpoint, 'POST');
requestOptions.headers = {
'Content-Type': 'multipart/mixed; boundary='+multipartBoundary,
'Accept': 'application/json'
Expand Down Expand Up @@ -1069,7 +1066,7 @@ function writeMetadata(document, categories) {
'Content-Type': 'application/json'
};

const requestOptions = mlutil.newRequestOptions(this.client.getConnectionParams(), endpoint, '&', 'PUT');
const requestOptions = mlutil.newRequestOptions(this.client.getConnectionParams(), endpoint, 'PUT');
requestOptions.headers = requestHeaders;
mlutil.addTxidHeaders(requestOptions, txid);

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

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

var writeParams = addWriteParams(requestParams, categories, txid);
var sep = '?';
if (writeParams.length > 0) {
endpoint += writeParams;
sep = '&';
}

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

const requestOptions = mlutil.newRequestOptions(this.client.getConnectionParams(), endpoint, sep, 'POST');
const requestOptions = mlutil.newRequestOptions(this.client.getConnectionParams(), endpoint, 'POST');
requestOptions.headers = requestHeaders;
mlutil.addTxidHeaders(requestOptions, txid);

Expand Down Expand Up @@ -1579,7 +1574,7 @@ function removeDocumentImpl(contentOnly, args) {
}
}

const requestOptions = mlutil.newRequestOptions(this.client.getConnectionParams(), path, '&','DELETE');
const requestOptions = mlutil.newRequestOptions(this.client.getConnectionParams(), path, 'DELETE');
if (versionId != null) {
requestOptions.headers = {
'If-Match': versionId
Expand Down Expand Up @@ -1692,7 +1687,7 @@ function removeAllDocumentsImpl(contentOnly, params) {
}
}

const requestOptions = mlutil.newRequestOptions(this.client.getConnectionParams(), endpoint, sep, 'DELETE');
const requestOptions = mlutil.newRequestOptions(this.client.getConnectionParams(), endpoint, 'DELETE');
mlutil.addTxidHeaders(requestOptions, txid);

var operation = new Operation(
Expand Down Expand Up @@ -1871,7 +1866,7 @@ function queryDocumentsImpl(collectionParam, contentOnly, builtQuery, timestamp,
}
}

const requestOptions = mlutil.newRequestOptions(this.client.getConnectionParams(), endpoint, '&', 'POST');
const requestOptions = mlutil.newRequestOptions(this.client.getConnectionParams(), endpoint, 'POST');
requestOptions.headers = {
'Content-Type': (isMultipart ?
'multipart/mixed; boundary='+multipartBoundary :
Expand Down Expand Up @@ -2068,7 +2063,7 @@ Documents.prototype.patch = function patchDocuments() {
patchBody.pathlang = pathlang;
}

const requestOptions = mlutil.newRequestOptions(this.client.getConnectionParams(), endpoint, '&', 'POST');
const requestOptions = mlutil.newRequestOptions(this.client.getConnectionParams(), endpoint, 'POST');
requestOptions.headers = {
'Content-Type':
((format === 'xml') ? 'application/xml' : 'application/json'),
Expand Down Expand Up @@ -2194,7 +2189,7 @@ Documents.prototype.suggest = function suggestDocuments() {
endpoint += '&limit=' + limit;
}

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

let path = '/v1/internal/forestinfo';
let connectionParams = this.client.getConnectionParams();
const requestOptions = mlutil.newRequestOptions(connectionParams, path, '&','GET');
const requestOptions = mlutil.newRequestOptions(connectionParams, path, 'GET');

requestOptions.headers = {
'Accept': 'application/json',
Expand Down Expand Up @@ -2493,7 +2488,7 @@ function queryAllDocumentsImpl(query, jobOptions) {
}

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

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

let path = '/v1/internal/forestinfo';
const requestOptions = mlutil.newRequestOptions(this.client.getConnectionParams(), path, '&', 'GET');
const requestOptions = mlutil.newRequestOptions(this.client.getConnectionParams(), path, 'GET');

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

function transformAllDocumentsImpl(inputStream, jobOptions){
let path = '/v1/internal/forestinfo';
const requestOptions = mlutil.newRequestOptions(this.client.getConnectionParams(), path, '&', 'GET');
const requestOptions = mlutil.newRequestOptions(this.client.getConnectionParams(), path, 'GET');

requestOptions.headers = {
'Accept': 'application/json',
Expand Down Expand Up @@ -3439,7 +3434,7 @@ function onTransformAllInit(output) {

jobState.endpoint = endpoint;

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

function removeAllUrisDocumentsImpl(inputStream, jobOptions){
let path = '/v1/internal/forestinfo';
const requestOptions = mlutil.newRequestOptions(this.client.getConnectionParams(), path, '&', 'GET');
const requestOptions = mlutil.newRequestOptions(this.client.getConnectionParams(), path, 'GET');

requestOptions.headers = {
'Accept': 'application/json',
Expand Down
6 changes: 3 additions & 3 deletions lib/endpoint-proxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ function emptyRequest(client, funcdef, args) {
}

const outputTransform = specifyOutputTransform(funcdef, requestHeaders);
const requestOptions = mlutil.newRequestOptions(client.getConnectionParams(), endpoint, '?', 'POST');
const requestOptions = mlutil.newRequestOptions(client.getConnectionParams(), endpoint, 'POST');
requestOptions.headers = requestHeaders;

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

checkArgNames(funcdef, args, requestHeaders);

const requestOptions = mlutil.newRequestOptions(client.getConnectionParams(), endpoint, '?', 'POST');
const requestOptions = mlutil.newRequestOptions(client.getConnectionParams(), endpoint, 'POST');
requestOptions.headers = requestHeaders;

const operation = new Operation(
Expand Down Expand Up @@ -92,7 +92,7 @@ function multiNodeRequest(client, funcdef, args) {

checkArgNames(funcdef, args, requestHeaders);

const requestOptions = mlutil.newRequestOptions(client.getConnectionParams(), endpoint, '?', 'POST');
const requestOptions = mlutil.newRequestOptions(client.getConnectionParams(), endpoint, 'POST');
requestOptions.headers = requestHeaders;

const operation = new Operation(
Expand Down
12 changes: 6 additions & 6 deletions lib/graphs.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ Graphs.prototype.read = function readGraph() {
}
}

const requestOptions = mlutil.newRequestOptions(this.client.getConnectionParams(), endpoint, '&', 'GET');
const requestOptions = mlutil.newRequestOptions(this.client.getConnectionParams(), endpoint, 'GET');
requestOptions.headers = {
'Accept': contentType
};
Expand Down Expand Up @@ -373,7 +373,7 @@ function changeGraph(action, isStreaming, args) {
if (sep === '?') { sep = '&'; }
}

const requestOptions = mlutil.newRequestOptions(this.client.getConnectionParams(), endpoint, sep, ((action === 'write') ? 'PUT' : 'POST'));
const requestOptions = mlutil.newRequestOptions(this.client.getConnectionParams(), endpoint, ((action === 'write') ? 'PUT' : 'POST'));
requestOptions.headers = {
'Content-Type': contentType
};
Expand Down Expand Up @@ -477,7 +477,7 @@ function applyGraph(action, args) {
if (sep === '?') { sep = '&'; }
}

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

var operation = new Operation(
action+' graph', this.client, requestOptions, 'empty', 'empty'
Expand Down Expand Up @@ -561,7 +561,7 @@ Graphs.prototype.list = function listGraphs() {
}
}

const requestOptions = mlutil.newRequestOptions(this.client.getConnectionParams(), endpoint, sep, 'GET');
const requestOptions = mlutil.newRequestOptions(this.client.getConnectionParams(), endpoint, 'GET');
if (!noContentType) {
requestOptions.headers = {
'Accept': contentType
Expand Down Expand Up @@ -752,7 +752,7 @@ Graphs.prototype.sparql = function queryGraphSPARQL() {
queryBody.search.sparql = query;
}

const requestOptions = mlutil.newRequestOptions(this.client.getConnectionParams(), endpoint, sep, 'POST');
const requestOptions = mlutil.newRequestOptions(this.client.getConnectionParams(), endpoint, 'POST');
requestOptions.headers = {
'Content-Type': contentType,
'Accept': acceptType
Expand Down Expand Up @@ -878,7 +878,7 @@ Graphs.prototype.sparqlUpdate = function updateGraphSPARQL() {
if (sep === '?') { sep = '&'; }
}

const requestOptions = mlutil.newRequestOptions(this.client.getConnectionParams(), endpoint, sep, 'POST');
const requestOptions = mlutil.newRequestOptions(this.client.getConnectionParams(), endpoint, 'POST');
requestOptions.headers = {
'Content-Type': 'application/sparql-update'
};
Expand Down
2 changes: 1 addition & 1 deletion lib/internal.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class InternalClass {
if(!path){
throw new Error('Path is needed to send request.');
}
let requestOptions = mlutil.newRequestOptions(this.clientObject.getConnectionParams(), path, '?');
let requestOptions = mlutil.newRequestOptions(this.clientObject.getConnectionParams(), path);
if (requestOptionsCallback) {
requestOptionsCallback(requestOptions);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/marklogic.js
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ MarkLogicClient.prototype.getConnectionParams = function getConnectionParams() {
* it contains httpStatusCode and httpStatusMessage properties identifying the failure.
*/
MarkLogicClient.prototype.checkConnection = function checkConnection() {
const requestOptions = mlutil.newRequestOptions(this.connectionParams, '/v1/ping', '?', 'HEAD');
const requestOptions = mlutil.newRequestOptions(this.connectionParams, '/v1/ping', 'HEAD');
var operation = new Operation(
'test operation', this, requestOptions, 'empty', 'empty'
);
Expand Down
14 changes: 12 additions & 2 deletions lib/mlutil.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ function endpointTransform(transform) {
}
}

function newRequestOptions(connectionParams, endpoint, separator, method) {
function newRequestOptions(connectionParams, endpoint, method) {
const requestOptions = copyProperties(connectionParams);
let database = connectionParams.database;
if(connectionParams.basePath) {
Expand All @@ -163,7 +163,17 @@ function newRequestOptions(connectionParams, endpoint, separator, method) {
}
requestOptions.method = method? method:'GET';

requestOptions.path = (database == null)? endpoint: (endpoint + separator + 'database=' + encodeURIComponent(database));
if (database !== null) {
if (endpoint.includes('?')) {
if (endpoint.endsWith('?')) {
requestOptions.path = (database == null) ? endpoint : (endpoint + 'database=' + encodeURIComponent(database));
} else {
requestOptions.path = (database == null) ? endpoint : (endpoint + '&database=' + encodeURIComponent(database));
}
} else {
requestOptions.path = (database == null) ? endpoint : (endpoint + '?database=' + encodeURIComponent(database));
}
}
return requestOptions;
}

Expand Down
2 changes: 1 addition & 1 deletion lib/resources-exec.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ function makeRequestOptions(client, args) {
}
}

const requestOptions = mlutil.newRequestOptions(client.getConnectionParams(), path, sep);
const requestOptions = mlutil.newRequestOptions(client.getConnectionParams(), path);
mlutil.addTxidHeaders(requestOptions, txid);

return requestOptions;
Expand Down
Loading

0 comments on commit f28ce95

Please sign in to comment.