Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 25 additions & 14 deletions lib/transforms.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ Transforms.prototype.read = function readTransform(name) {
* @param {string} name - the name of the transform
* @param {string} format - a value from the javascript|xquery|xslt enumeration
* @param {object|string} source - the source for the transform
* @param {object} [transformParams] - an object mapping parameter names to their
* XQuery SequenceType declarations (including cardinality such as *, ?, etc.)
*/
Transforms.prototype.write = function writeTransform() {
const args = mlutil.asArray.apply(null, arguments);
Expand All @@ -88,24 +90,26 @@ Transforms.prototype.write = function writeTransform() {
throw new Error('no arguments for writing an extension library');
}

let name = null;
let title = null;
let description = null;
let provider = null;
let version = null;
let format = null;
let source = null;
let name = null;
let title = null;
let description = null;
let provider = null;
let version = null;
let format = null;
let source = null;
let transformParams = null;

let params = null;
if (argLen === 1) {
params = args[0];
name = params.name;
title = params.title;
description = params.description;
provider = params.provider;
version = params.version;
format = params.format;
source = params.source;
name = params.name;
title = params.title;
description = params.description;
provider = params.provider;
version = params.version;
format = params.format;
source = params.source;
transformParams = params.transformParams;
} else if (argLen > 2){
name = args[0];
format = args[1];
Expand Down Expand Up @@ -152,6 +156,13 @@ Transforms.prototype.write = function writeTransform() {
if (sep === '?') {sep = '&';}
}

if (transformParams != null) {
for (const [paramName, paramType] of Object.entries(transformParams)) {
endpoint += sep+'trans:'+encodeURIComponent(paramName)+'='+encodeURIComponent(paramType);
if (sep === '?') {sep = '&';}
}
}

const requestOptions = mlutil.copyProperties(this.client.getConnectionParams());
requestOptions.method = 'PUT';
requestOptions.headers = {
Expand Down
36 changes: 32 additions & 4 deletions test-basic/documents-transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ describe('document transform', function(){
})
.catch(done);
});

it('should write the transform with named parameters', function(done){
this.timeout(3000);
restAdminDB.config.transforms.write({
Expand All @@ -35,13 +36,18 @@ describe('document transform', function(){
provider: 'Banner Business',
version: 0.1,
format: 'xquery',
source: fs.createReadStream(xqyTransformPath)
source: fs.createReadStream(xqyTransformPath),
transformParams: {
'flag': 'xs:string?',
'count': 'xs:integer*'
}
})
.result(function(response){
done();
})
.catch(done);
});

it('should read the transform', function(done){
restAdminDB.config.transforms.read(xqyTransformName)
.result(function(source){
Expand All @@ -51,19 +57,35 @@ describe('document transform', function(){
})
.catch(done);
});

it('should list the transform', function(done){
db.config.transforms.list()
.result(function(response){
response.should.have.property('transforms');
response.transforms.should.have.property('transform');
response.transforms.transform.length.should.be.greaterThan(0);
response.transforms.transform.some(function(item){

const flagTransform = response.transforms.transform.find(function(item){
return item.name === xqyTransformName;
}).should.equal(true);
});
should.exist(flagTransform);
flagTransform.should.have.property('transform-parameters');
flagTransform['transform-parameters'].should.have.property('parameter');

const params = flagTransform['transform-parameters'].parameter;
params.should.be.an.Array();
params.length.should.equal(2);
params.some(function(p){
return p['parameter-name'] === 'flag' && p['parameter-type'] === 'xs:string?';
}).should.equal(true);
params.some(function(p){
return p['parameter-name'] === 'count' && p['parameter-type'] === 'xs:integer*';
}).should.equal(true);
done();
})
})
.catch(done);
});

it('should delete the transform', function(done){
restAdminDB.config.transforms.remove(xqyTransformName)
.result(function(response){
Expand All @@ -83,6 +105,7 @@ describe('document transform', function(){
})
.catch(done);
});

it('should modify during write', function(done){
db.documents.write({
uri: uri,
Expand All @@ -100,6 +123,7 @@ describe('document transform', function(){
})
.catch(done);
});

it('should modify during read', function(done){
db.documents.read({
uris: uri,
Expand All @@ -112,6 +136,7 @@ describe('document transform', function(){
})
.catch(done);
});

it('should modify during query', function(done){
db.documents.query(
q.where(
Expand Down Expand Up @@ -147,6 +172,7 @@ describe('document transform', function(){
.then(function(response){done();})
.catch(done);
});

it('should modify during write', function(done){
db.documents.write({
uri: writeUri,
Expand All @@ -166,6 +192,7 @@ describe('document transform', function(){
})
.catch(done);
});

it('should modify during read', function(done){
db.documents.read({
uris: readUri,
Expand All @@ -180,6 +207,7 @@ describe('document transform', function(){
})
.catch(done);
});

it('should modify during query', function(done){
db.documents.query(
q.where(
Expand Down
Loading