Skip to content

Commit 8085214

Browse files
MariusSameeraPriyathamTadikonda
authored andcommitted
DEVEXP-281: transformDoc implementation in node-client-api
1 parent 1817184 commit 8085214

File tree

6 files changed

+387
-1
lines changed

6 files changed

+387
-1
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
const result = {"hello": "world",
2+
"Patch1": external.patch1,
3+
"Patch2": external.patch2,
4+
"theDoc": external.doc}
5+
result

etc/data/transformDoc-test.mjs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
const result = {
2+
"hello": "world",
3+
"yourParam": external.myParam,
4+
"theDoc": external.doc
5+
}
6+
result

etc/data/transformDoc-test.xslt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
3+
<xsl:param name="myParam" />
4+
<xsl:template match="/">
5+
<result>
6+
<xsl:copy-of select="/"/>
7+
<hello>world</hello>
8+
<yourParam><xsl:value-of select="$myParam"/></yourParam>
9+
</result>
10+
</xsl:template>
11+
</xsl:stylesheet>

etc/test-setup.js

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,43 @@ const moduleFiles = [
8989
{'role-name':testconfig.restAdminConnection.user, capabilities:['read', 'execute', 'update']}
9090
],
9191
content:fs.createReadStream('./etc/data/articleCitation.json')
92-
}];
92+
}, {
93+
uri:'/optic/test/transformDoc-test.mjs',
94+
contentType:'application/vnd.marklogic-javascript',
95+
permissions: [
96+
{'role-name':'app-user', capabilities:['read', 'execute']},
97+
{'role-name':'app-builder', capabilities:['read', 'execute']},
98+
{'role-name':testconfig.restReaderConnection.user, capabilities:['read', 'execute', 'update']},
99+
{'role-name':testconfig.restWriterConnection.user, capabilities:['read', 'execute', 'update']},
100+
{'role-name':testconfig.restAdminConnection.user, capabilities:['read', 'execute', 'update']}
101+
],
102+
content:fs.createReadStream('./etc/data/transformDoc-test.mjs')
103+
},
104+
{
105+
uri:'/optic/test/transformDoc-test.xslt',
106+
contentType:'application/vnd.marklogic-tde+xml',
107+
permissions: [
108+
{'role-name':'app-user', capabilities:['read', 'execute']},
109+
{'role-name':'app-builder', capabilities:['read', 'execute']},
110+
{'role-name':testconfig.restReaderConnection.user, capabilities:['read', 'execute', 'update']},
111+
{'role-name':testconfig.restWriterConnection.user, capabilities:['read', 'execute', 'update']},
112+
{'role-name':testconfig.restAdminConnection.user, capabilities:['read', 'execute', 'update']}
113+
],
114+
content:fs.createReadStream('./etc/data/transformDoc-test.xslt')
115+
},
116+
{
117+
uri:'/optic/test/transformDoc-test-two-params.mjs',
118+
contentType:'application/vnd.marklogic-tde+xml',
119+
permissions: [
120+
{'role-name':'app-user', capabilities:['read', 'execute']},
121+
{'role-name':'app-builder', capabilities:['read', 'execute']},
122+
{'role-name':testconfig.restReaderConnection.user, capabilities:['read', 'execute', 'update']},
123+
{'role-name':testconfig.restWriterConnection.user, capabilities:['read', 'execute', 'update']},
124+
{'role-name':testconfig.restAdminConnection.user, capabilities:['read', 'execute', 'update']}
125+
],
126+
content:fs.createReadStream('./etc/data/transformDoc-test-two-params.mjs')
127+
}
128+
];
93129

94130
const dataFiles = [
95131
{

lib/plan-builder-base.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,35 @@ function castArg(arg, funcName, paramName, argPos, paramTypes) {
315315
return true;
316316
}
317317
});
318+
case 'PlanTransformDef':
319+
return Object.keys(arg).every(key => {
320+
const value = arg[key];
321+
const type = typeof value;
322+
if(key === 'path') {
323+
if(type !== "string") {
324+
throw new Error(
325+
`${argLabel(funcName, paramName, argPos)} should be a type of string`
326+
);
327+
}
328+
return true;
329+
}
330+
if(key === 'kind') {
331+
if(type !== 'string') {
332+
throw new Error(
333+
`${argLabel(funcName, paramName, argPos)} should be a type of string`
334+
);
335+
}
336+
return true;
337+
}
338+
if(key === 'params') {
339+
if(type !== "object") {
340+
throw new Error(
341+
`${argLabel(funcName, paramName, argPos)} should be a type of object`
342+
);
343+
}
344+
}
345+
return true;
346+
});
318347
case 'PlanRowColTypes':
319348
const objKeys = Object.keys(arg);
320349
if(!objKeys.includes('column')) {

0 commit comments

Comments
 (0)