Skip to content

Commit 4346c92

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 4346c92

File tree

2 files changed

+54
-18
lines changed

2 files changed

+54
-18
lines changed

lib/transforms.js

Lines changed: 24 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];
@@ -151,6 +155,12 @@ Transforms.prototype.write = function writeTransform() {
151155
endpoint += sep+'version='+encodeURIComponent(version);
152156
if (sep === '?') {sep = '&';}
153157
}
158+
if (transformParams != null) {
159+
for (const [paramName, paramType] of Object.entries(transformParams)) {
160+
endpoint += sep+'trans:'+encodeURIComponent(paramName)+'='+encodeURIComponent(paramType);
161+
if (sep === '?') {sep = '&';}
162+
}
163+
}
154164

155165
const requestOptions = mlutil.copyProperties(this.client.getConnectionParams());
156166
requestOptions.method = 'PUT';

test-basic/documents-transform.js

Lines changed: 30 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,33 @@ 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+
var flagTransform = response.transforms.transform.find(function(item){
6168
return item.name === xqyTransformName;
62-
}).should.equal(true);
69+
});
70+
should.exist(flagTransform);
71+
flagTransform.should.have.property('transform-parameters');
72+
flagTransform['transform-parameters'].should.have.property('parameter');
73+
var params = flagTransform['transform-parameters'].parameter;
74+
params.should.be.an.Array();
75+
params.length.should.equal(2);
76+
params.some(function(p){
77+
return p['parameter-name'] === 'flag' && p['parameter-type'] === 'xs:string?';
78+
}).should.equal(true);
79+
params.some(function(p){
80+
return p['parameter-name'] === 'count' && p['parameter-type'] === 'xs:integer*';
81+
}).should.equal(true);
6382
done();
64-
})
83+
})
6584
.catch(done);
6685
});
86+
6787
it('should delete the transform', function(done){
6888
restAdminDB.config.transforms.remove(xqyTransformName)
6989
.result(function(response){
@@ -83,6 +103,7 @@ describe('document transform', function(){
83103
})
84104
.catch(done);
85105
});
106+
86107
it('should modify during write', function(done){
87108
db.documents.write({
88109
uri: uri,
@@ -100,6 +121,7 @@ describe('document transform', function(){
100121
})
101122
.catch(done);
102123
});
124+
103125
it('should modify during read', function(done){
104126
db.documents.read({
105127
uris: uri,
@@ -112,6 +134,7 @@ describe('document transform', function(){
112134
})
113135
.catch(done);
114136
});
137+
115138
it('should modify during query', function(done){
116139
db.documents.query(
117140
q.where(
@@ -147,6 +170,7 @@ describe('document transform', function(){
147170
.then(function(response){done();})
148171
.catch(done);
149172
});
173+
150174
it('should modify during write', function(done){
151175
db.documents.write({
152176
uri: writeUri,
@@ -166,6 +190,7 @@ describe('document transform', function(){
166190
})
167191
.catch(done);
168192
});
193+
169194
it('should modify during read', function(done){
170195
db.documents.read({
171196
uris: readUri,
@@ -180,6 +205,7 @@ describe('document transform', function(){
180205
})
181206
.catch(done);
182207
});
208+
183209
it('should modify during query', function(done){
184210
db.documents.query(
185211
q.where(

0 commit comments

Comments
 (0)