mushroom-cli 1.1.0 → 1.2.0-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -0
- package/gen/gen-ts-driver.js +23 -14
- package/package.json +2 -2
package/README.md
CHANGED
package/gen/gen-ts-driver.js
CHANGED
|
@@ -63,26 +63,27 @@ function getCSharpTypeFromMushroomType(type) {
|
|
|
63
63
|
return "UNKNOWN_TYPE_" + type;
|
|
64
64
|
}
|
|
65
65
|
|
|
66
|
-
function generateTypescriptClass(objectDefination, indent) {
|
|
66
|
+
function generateTypescriptClass(objectDefination, indent, options) {
|
|
67
67
|
if (!indent) indent = "";
|
|
68
68
|
let code = "{\n";
|
|
69
69
|
for (let fieldName in objectDefination) {
|
|
70
|
+
const optionalMark = options?.checkRequired && objectDefination[fieldName].required ? "" : "?";
|
|
70
71
|
if (objectDefination[fieldName].type == "object") {
|
|
71
|
-
code += `${indent} ${fieldName}
|
|
72
|
+
code += `${indent} ${fieldName}${optionalMark}: ${generateTypescriptClass(objectDefination[fieldName].fields, indent + " ")},
|
|
72
73
|
`;
|
|
73
74
|
}
|
|
74
75
|
else if (objectDefination[fieldName].type == "array") {
|
|
75
76
|
if (objectDefination[fieldName].items.type == "object") {
|
|
76
|
-
code += `${indent} ${fieldName}
|
|
77
|
+
code += `${indent} ${fieldName}${optionalMark}: ${generateTypescriptClass(objectDefination[fieldName].items.fields, indent + " ")}[],
|
|
77
78
|
`;
|
|
78
79
|
}
|
|
79
80
|
else {
|
|
80
|
-
code += `${indent} ${fieldName}
|
|
81
|
+
code += `${indent} ${fieldName}${optionalMark}: ${getCSharpTypeFromMushroomType(objectDefination[fieldName].items.type)}[],
|
|
81
82
|
`;
|
|
82
83
|
}
|
|
83
84
|
}
|
|
84
85
|
else {
|
|
85
|
-
code += `${indent} ${fieldName}
|
|
86
|
+
code += `${indent} ${fieldName}${optionalMark}: ${getCSharpTypeFromMushroomType(objectDefination[fieldName].type)},
|
|
86
87
|
`;
|
|
87
88
|
}
|
|
88
89
|
}
|
|
@@ -92,7 +93,7 @@ function generateTypescriptClass(objectDefination, indent) {
|
|
|
92
93
|
|
|
93
94
|
function generateTypescriptClassFromViewParameters(parameters) {
|
|
94
95
|
if (Array.isArray(parameters)){
|
|
95
|
-
return '{\n' + parameters.map(p => ` ${p.field}
|
|
96
|
+
return '{\n' + parameters.map(p => ` ${p.field}${p.validation?.required ? "" : "?"}: ${getCSharpTypeFromMushroomType(p.type || "string")}${p.isArray ? "[]" : ""}`).join(',\n') + '\n}';
|
|
96
97
|
}
|
|
97
98
|
return '{}';
|
|
98
99
|
}
|
|
@@ -227,13 +228,17 @@ ${customMethodCode}}
|
|
|
227
228
|
views[viewName] = { clientCache: true };
|
|
228
229
|
|
|
229
230
|
const viewParameterTypes = viewRoles.map(view => {
|
|
230
|
-
const
|
|
231
|
-
|
|
231
|
+
const inputType = `${typescriptClassName}$ViewsResource_${viewName}View_${view.grant === "*" ? "" : toTypeScriptClassName(view.grant)}Parameters`;
|
|
232
|
+
const outputType = view.codeHint?.output ? `${typescriptClassName}$ViewsResource_${viewName}View_${view.grant === "*" ? "" : toTypeScriptClassName(view.grant)}Result` : 'any';
|
|
233
|
+
code += `export interface ${inputType} ${generateTypescriptClassFromViewParameters(view.parameters)};
|
|
232
234
|
`;
|
|
233
|
-
|
|
235
|
+
if (view.codeHint?.output)
|
|
236
|
+
code += `export interface ${outputType} ${generateTypescriptClass(view.codeHint.output.fields, undefined, {checkRequired: true})};
|
|
237
|
+
`;
|
|
238
|
+
return `MushroomViewFunction<${outputType}, ${inputType}>`;
|
|
234
239
|
});
|
|
235
240
|
viewCode += `
|
|
236
|
-
${viewName}Async: ${viewParameterTypes.join('
|
|
241
|
+
${viewName}Async: ${viewParameterTypes.join(' | ')},`;
|
|
237
242
|
}
|
|
238
243
|
|
|
239
244
|
if (viewCode) {
|
|
@@ -396,13 +401,17 @@ ${customMethodCode}}
|
|
|
396
401
|
views[viewName] = { clientCache: true };
|
|
397
402
|
|
|
398
403
|
const viewParameterTypes = viewRoles.map(view => {
|
|
399
|
-
const
|
|
400
|
-
|
|
404
|
+
const inputType = `${typescriptClassName}$ViewsResource_${viewName}View_${view.grant === "*" ? "" : toTypeScriptClassName(view.grant)}Parameters`;
|
|
405
|
+
const outputType = view.codeHint?.output ? `${typescriptClassName}$ViewsResource_${viewName}View_${view.grant === "*" ? "" : toTypeScriptClassName(view.grant)}Result` : 'any';
|
|
406
|
+
code += `export interface ${inputType} ${generateTypescriptClassFromViewParameters(view.parameters)};
|
|
407
|
+
`;
|
|
408
|
+
if (view.codeHint?.output)
|
|
409
|
+
code += `export interface ${outputType} ${generateTypescriptClass(view.codeHint.output.fields, undefined, {checkRequired: true})};
|
|
401
410
|
`;
|
|
402
|
-
return `MushroomViewFunction
|
|
411
|
+
return `MushroomViewFunction<${outputType}, ${inputType}>`;
|
|
403
412
|
});
|
|
404
413
|
viewCode += `
|
|
405
|
-
${viewName}Async: ${viewParameterTypes.join('
|
|
414
|
+
${viewName}Async: ${viewParameterTypes.join(' | ')},`;
|
|
406
415
|
}
|
|
407
416
|
|
|
408
417
|
if (viewCode) {
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mushroom-cli",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.0-alpha.1",
|
|
4
4
|
"description": "Mushroom CLI",
|
|
5
5
|
"main": "mr.js",
|
|
6
6
|
"scripts": {
|
|
7
|
-
"release": "npm publish --access public"
|
|
7
|
+
"release": "npm publish --access public --tag alpha"
|
|
8
8
|
},
|
|
9
9
|
"keywords": [
|
|
10
10
|
"Mushroom",
|