Skip to content

Commit e7dd6cf

Browse files
committed
MLE-25579 Can now specify transform params when writing a transform
When transforms did lack the power to declare What parameters they would deign to receive, Developers were left in dark despair, With undocumented args they could not believe. But lo! transformParams now graces the write, A simple object of name and type pairs, From xs:string? to xs:integer's might, The query string now carries all affairs. trans:flag and trans:count now ride along, URL-encoded, proper, clean, and true, The list endpoint sings a validating song, Confirming params registered on cue. So merge this branch with confidence and cheer, For typed transform params are finally here!
1 parent e1c03ae commit e7dd6cf

File tree

2 files changed

+57
-18
lines changed

2 files changed

+57
-18
lines changed

lib/transforms.js

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@ Transforms.prototype.read = function readTransform(name) {
8080
* @param {string} name - the name of the transform
8181
* @param {string} format - a value from the javascript|xquery|xslt enumeration
8282
* @param {object|string} source - the source for the transform
83+
* @param {object} [transformParams] - an object mapping parameter names to their
84+
* XQuery SequenceType declarations (including cardinality such as *, ?, etc.)
8385
*/
8486
Transforms.prototype.write = function writeTransform() {
8587
const args = mlutil.asArray.apply(null, arguments);
@@ -88,24 +90,26 @@ Transforms.prototype.write = function writeTransform() {
8890
throw new Error('no arguments for writing an extension library');
8991
}
9092

91-
let name = null;
92-
let title = null;
93-
let description = null;
94-
let provider = null;
95-
let version = null;
96-
let format = null;
97-
let source = null;
93+
let name = null;
94+
let title = null;
95+
let description = null;
96+
let provider = null;
97+
let version = null;
98+
let format = null;
99+
let source = null;
100+
let transformParams = null;
98101

99102
let params = null;
100103
if (argLen === 1) {
101104
params = args[0];
102-
name = params.name;
103-
title = params.title;
104-
description = params.description;
105-
provider = params.provider;
106-
version = params.version;
107-
format = params.format;
108-
source = params.source;
105+
name = params.name;
106+
title = params.title;
107+
description = params.description;
108+
provider = params.provider;
109+
version = params.version;
110+
format = params.format;
111+
source = params.source;
112+
transformParams = params.transformParams;
109113
} else if (argLen > 2){
110114
name = args[0];
111115
format = args[1];
@@ -152,6 +156,13 @@ Transforms.prototype.write = function writeTransform() {
152156
if (sep === '?') {sep = '&';}
153157
}
154158

159+
if (transformParams != null) {
160+
for (const [paramName, paramType] of Object.entries(transformParams)) {
161+
endpoint += sep+'trans:'+encodeURIComponent(paramName)+'='+encodeURIComponent(paramType);
162+
if (sep === '?') {sep = '&';}
163+
}
164+
}
165+
155166
const requestOptions = mlutil.copyProperties(this.client.getConnectionParams());
156167
requestOptions.method = 'PUT';
157168
requestOptions.headers = {

test-basic/documents-transform.js

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ describe('document transform', function(){
2626
})
2727
.catch(done);
2828
});
29+
2930
it('should write the transform with named parameters', function(done){
3031
this.timeout(3000);
3132
restAdminDB.config.transforms.write({
@@ -35,13 +36,18 @@ describe('document transform', function(){
3536
provider: 'Banner Business',
3637
version: 0.1,
3738
format: 'xquery',
38-
source: fs.createReadStream(xqyTransformPath)
39+
source: fs.createReadStream(xqyTransformPath),
40+
transformParams: {
41+
'flag': 'xs:string?',
42+
'count': 'xs:integer*'
43+
}
3944
})
4045
.result(function(response){
4146
done();
4247
})
4348
.catch(done);
4449
});
50+
4551
it('should read the transform', function(done){
4652
restAdminDB.config.transforms.read(xqyTransformName)
4753
.result(function(source){
@@ -51,19 +57,35 @@ describe('document transform', function(){
5157
})
5258
.catch(done);
5359
});
60+
5461
it('should list the transform', function(done){
5562
db.config.transforms.list()
5663
.result(function(response){
5764
response.should.have.property('transforms');
5865
response.transforms.should.have.property('transform');
5966
response.transforms.transform.length.should.be.greaterThan(0);
60-
response.transforms.transform.some(function(item){
67+
68+
const flagTransform = response.transforms.transform.find(function(item){
6169
return item.name === xqyTransformName;
62-
}).should.equal(true);
70+
});
71+
should.exist(flagTransform);
72+
flagTransform.should.have.property('transform-parameters');
73+
flagTransform['transform-parameters'].should.have.property('parameter');
74+
75+
const params = flagTransform['transform-parameters'].parameter;
76+
params.should.be.an.Array();
77+
params.length.should.equal(2);
78+
params.some(function(p){
79+
return p['parameter-name'] === 'flag' && p['parameter-type'] === 'xs:string?';
80+
}).should.equal(true);
81+
params.some(function(p){
82+
return p['parameter-name'] === 'count' && p['parameter-type'] === 'xs:integer*';
83+
}).should.equal(true);
6384
done();
64-
})
85+
})
6586
.catch(done);
6687
});
88+
6789
it('should delete the transform', function(done){
6890
restAdminDB.config.transforms.remove(xqyTransformName)
6991
.result(function(response){
@@ -83,6 +105,7 @@ describe('document transform', function(){
83105
})
84106
.catch(done);
85107
});
108+
86109
it('should modify during write', function(done){
87110
db.documents.write({
88111
uri: uri,
@@ -100,6 +123,7 @@ describe('document transform', function(){
100123
})
101124
.catch(done);
102125
});
126+
103127
it('should modify during read', function(done){
104128
db.documents.read({
105129
uris: uri,
@@ -112,6 +136,7 @@ describe('document transform', function(){
112136
})
113137
.catch(done);
114138
});
139+
115140
it('should modify during query', function(done){
116141
db.documents.query(
117142
q.where(
@@ -147,6 +172,7 @@ describe('document transform', function(){
147172
.then(function(response){done();})
148173
.catch(done);
149174
});
175+
150176
it('should modify during write', function(done){
151177
db.documents.write({
152178
uri: writeUri,
@@ -166,6 +192,7 @@ describe('document transform', function(){
166192
})
167193
.catch(done);
168194
});
195+
169196
it('should modify during read', function(done){
170197
db.documents.read({
171198
uris: readUri,
@@ -180,6 +207,7 @@ describe('document transform', function(){
180207
})
181208
.catch(done);
182209
});
210+
183211
it('should modify during query', function(done){
184212
db.documents.query(
185213
q.where(

0 commit comments

Comments
 (0)