Skip to content

Commit 962c526

Browse files
authored
Create template.js
Added a starter template for a transform data resource. This template contains: - JSDoc type annotations - Destructured inputs - Try/catch - Error logging then throw (Enables error logging but still allows the data resource to fail) - An example of what the properties object should look like
1 parent 3ae1cc4 commit 962c526

File tree

1 file changed

+64
-0
lines changed

1 file changed

+64
-0
lines changed
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/**
2+
* This is a starter template for a transform data broker with:
3+
* - JSDoc type annotations
4+
* - Destructured inputs
5+
* - Try/catch
6+
* - Error logging then throw (Enables error logging but still allows the data resource to fail)
7+
* @param {{param1: string, param2: number, param3: [boolean]}} inputs inputs from the properties field above, param1 and param2 are mandatory
8+
* @returns {string} the value returned
9+
*/
10+
function transform({ param1, param2, param3 }) {
11+
const lib = "Data Broker";
12+
const func = "<insert data broker name here>";
13+
14+
/** @type {string} */
15+
let res;
16+
17+
try {
18+
// Handle required param checks
19+
if (!param1) throw new Error("Missing required param 'param1'");
20+
if (!param2) throw new Error("Missing required param 'param2'");
21+
22+
// Add logic here
23+
24+
return res;
25+
} catch (e) {
26+
gs.error(`${lib} ${func} - ${e}`);
27+
throw new Error(e);
28+
}
29+
}
30+
31+
/**
32+
* TIPS
33+
* Make sure to flag mutates data if your data resource changes any data
34+
* Properties structure (these are the inputs for your data resource):
35+
[
36+
{
37+
"name": "param1",
38+
"label": "Param 1",
39+
"description": "An example of the first param as a string, mandatory",
40+
"readOnly": false,
41+
"fieldType": "string",
42+
"mandatory": true,
43+
"defaultValue": ""
44+
},
45+
{
46+
"name": "param2",
47+
"label": "Param 2",
48+
"description": "An example of the second param as a number, mandatory",
49+
"readOnly": false,
50+
"fieldType": "number",
51+
"mandatory": true,
52+
"defaultValue": ""
53+
},
54+
{
55+
"name": "param3",
56+
"label": "Param 3",
57+
"description": "An example of the third param as a boolean, optional",
58+
"readOnly": false,
59+
"fieldType": "boolean",
60+
"mandatory": false,
61+
"defaultValue": ""
62+
}
63+
]
64+
*/

0 commit comments

Comments
 (0)