mushroom-cli 1.2.0-alpha.20 → 1.2.0-alpha.21

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 CHANGED
@@ -132,6 +132,13 @@ npx mushroom-cli parameters --no-check-update
132
132
 
133
133
  ## Version
134
134
 
135
+ ### 1.2.0-alpha.21
136
+
137
+ Improvement:
138
+
139
+ - gen-docs
140
+ - generate docs for response body of custom methods
141
+
135
142
  ### 1.2.0-alpha.20
136
143
 
137
144
  Improvement:
package/dist/common.js CHANGED
@@ -52,17 +52,16 @@ export function getEntities(projectApiConfiguration, roles, getAll) {
52
52
  if (!action.grant || !action.enabled || (action.codeHint && action.codeHint.disabled))
53
53
  return;
54
54
  let allow = roles?.includes('*') || action.grant === '*';
55
- if (!allow)
56
- action.grant.split('|').forEach(function (roleGroup) {
55
+ if (!allow) {
56
+ action.grant = action.grant.split('|').map(roleGroup => {
57
57
  if (!roleGroup)
58
- return;
59
- roleGroup.split('+').forEach(function (grantedRole) {
60
- if (roles?.indexOf(grantedRole) !== -1)
61
- allow = true;
62
- });
63
- });
64
- if (!allow)
65
- return;
58
+ return null;
59
+ const ok = roleGroup.split('+').every(grantedRole => roles?.includes(grantedRole));
60
+ return ok ? roleGroup : null;
61
+ }).filter(roleGroup => roleGroup).join('|');
62
+ if (!action.grant)
63
+ return;
64
+ }
66
65
  if (!(entity.name in entities)) {
67
66
  entities[entity.name] = {
68
67
  name: entity.name,
@@ -78,21 +77,21 @@ export function getEntities(projectApiConfiguration, roles, getAll) {
78
77
  });
79
78
  }
80
79
  for (const viewName in entity.views) {
81
- entity.views[viewName].forEach(function (view) {
80
+ entity.views[viewName].forEach((view) => {
82
81
  var _a;
83
82
  if (!view.grant || !view.enabled)
84
83
  return;
85
84
  let allow = roles?.indexOf('*') !== -1 || view.grant === '*';
86
- view.grant.split('|').forEach(function (roleGroup) {
87
- if (!roleGroup)
85
+ if (!allow) {
86
+ view.grant = view.grant.split('|').map(roleGroup => {
87
+ if (!roleGroup)
88
+ return null;
89
+ const ok = roleGroup.split('+').every(grantedRole => roles?.includes(grantedRole));
90
+ return ok ? roleGroup : null;
91
+ }).filter(roleGroup => roleGroup).join('|');
92
+ if (!view.grant)
88
93
  return;
89
- roleGroup.split('+').forEach(function (grantedRole) {
90
- if (roles?.indexOf(grantedRole) !== -1)
91
- allow = true;
92
- });
93
- });
94
- if (!allow)
95
- return;
94
+ }
96
95
  if (!(entity.name in entities)) {
97
96
  entities[entity.name] = {
98
97
  name: entity.name,
@@ -4424,34 +4424,19 @@ catch (Exception ex)
4424
4424
  <script type="text/mushroom-docs-template" class="mushroom-docs-template" id="template-codeSnippets-generalAction-HTTP">
4425
4425
  <div class="http-snippet">
4426
4426
  Code tham khảo:
4427
- <pre data-language="http">{{httpMethod}} {{rootUrlPath}}{{entityName}}s/{{httpMethod}}<span class="place-holder">?param1=value1&amp;param2=value2</span> HTTP/1.1
4428
- Host: <span class="domain">{{domain}}</span>
4429
- Content-Type: application/json<span style="display: {{tokenDisplay}}">
4430
- X-HTTP-Method-Override: {{httpMethod}}
4431
- Token: your token</span>
4432
-
4433
- <span class="place-holder">BODY DATA</span></pre>
4434
- <pre data-language="http"><span style="display: {{bodyDisplay}}">TRƯỜNG HỢP CÓ BODY DATA</span>
4435
- POST {{rootUrlPath}}{{entityName}}s/{{httpMethod}}<span class="place-holder">?param1=value1&amp;param2=value2</span> HTTP/1.1
4427
+ <pre data-language="http">POST {{rootUrlPath}}{{entityName}}s/{{httpMethod}}<span class="place-holder">?param1=value1&amp;param2=value2</span> HTTP/1.1
4436
4428
  Host: <span class="domain">{{domain}}</span>
4437
4429
  Content-Type: application/json
4438
4430
  X-HTTP-Method-Override: {{httpMethod}}<span style="display: {{tokenDisplay}}">
4439
4431
  Token: your token</span>
4440
4432
 
4441
- <span class="place-holder">BODY DATA</span>
4442
- <span style="display: {{noBodyDisplay}}">
4443
- TRƯỜNG HỢP KHÔNG CÓ BODY DATA
4444
- GET {{rootUrlPath}}{{entityName}}s/{{httpMethod}}<span class="place-holder">?param1=value1&amp;param2=value2</span> HTTP/1.1
4445
- Host: <span class="domain">{{domain}}</span>
4446
- Content-Type: application/json
4447
- X-HTTP-Method-Override: {{httpMethod}}<span style="display: {{tokenDisplay}}">
4448
- Token: your token</span></span></pre>
4433
+ <span class="place-holder">BODY DATA IF ANY</span></pre>
4449
4434
  </div>
4450
4435
  </script>
4451
4436
  <script type="text/mushroom-docs-template" class="mushroom-docs-template" id="template-codeSnippets-generalAction-cURL">
4452
4437
  <div class="curl-snippet">
4453
4438
  cURL
4454
- <pre data-language="cURL">curl -X {{httpMethod}} \
4439
+ <pre data-language="cURL">curl -X POST \
4455
4440
  '<span class="root-url">{{rootUrl}}</span>{{entityName}}s/{{httpMethod}}<span class="place-holder">?param1=value1&amp;param2=value2</span>' \
4456
4441
  -H 'Content-Type: application/json' \
4457
4442
  -H 'X-HTTP-Method-Override: {{httpMethod}}' \<span style="display: {{tokenDisplay}}">
@@ -4459,7 +4444,7 @@ Token: your token</span></span></pre>
4459
4444
  -d 'BODY DATA IF ANY'
4460
4445
  </pre>
4461
4446
  Shell
4462
- <pre data-language="cURL">curl --request {{httpMethod}} \
4447
+ <pre data-language="cURL">curl --request POST \
4463
4448
  --url '<span class="root-url">{{rootUrl}}</span>{{entityName}}s/{{httpMethod}}<span class="place-holder">?param1=value1&amp;param2=value2</span>' \
4464
4449
  --header 'X-HTTP-Method-Override: {{httpMethod}}' \<span style="display: {{tokenDisplay}}">
4465
4450
  --header 'Token: {<span>{</span>TOKEN}}' \</span>
@@ -5010,6 +4995,10 @@ API.get{{EntityName}}().getViews().{{viewName}}Async(arg, result -> {
5010
4995
  <h4>Request body</h4>
5011
4996
  <pre class="request-body-model"></pre>
5012
4997
  </div>
4998
+ <div class="response-body">
4999
+ <h4>Response body</h4>
5000
+ <pre class="response-body-model"></pre>
5001
+ </div>
5013
5002
  </div>
5014
5003
 
5015
5004
 
@@ -387,7 +387,7 @@ function formatHintModel(obj, strIndent, options) {
387
387
  validation += ', enum(' + encodeHtml(child.items.validValues.join(', ')) + ')';
388
388
  }
389
389
 
390
- var comment = `<span class="code-comment">// ${validation} ${typeof child.description === 'string' && child.description !== '' ? '- ' + encodeHtml(child.description) : ''}</span>`;
390
+ var comment = `<span class="code-comment">// ${validation} ${typeof child.description === 'string' && child.description !== '' ? '- ' + encodeHtml(child.description).replace(/\n/g, ' ') : ''}</span>`;
391
391
 
392
392
  if (options.mode === 'model') {
393
393
  if (child.type === 'object')
@@ -1007,17 +1007,33 @@ function renderGeneralAction(args) {
1007
1007
  if (args.action?.codeHint?.delegator?.param?.fields) {
1008
1008
  args.tabPage.querySelector('.query-string-model').innerHTML = formatHintModel(
1009
1009
  args.action.codeHint.delegator.param.fields,
1010
- );
1010
+ ).trim();
1011
1011
  } else {
1012
1012
  args.tabPage.querySelector('.query-string')?.remove();
1013
1013
  }
1014
1014
  if (args.action?.codeHint?.delegator?.requestBody?.fields) {
1015
1015
  args.tabPage.querySelector('.request-body-model').innerHTML = formatHintModel(
1016
1016
  args.action.codeHint.delegator.requestBody.fields,
1017
- );
1017
+ ).trim();
1018
+ } else if (args.action?.codeHint?.delegator?.requestBody?.items?.fields) {
1019
+ args.tabPage.querySelector('.request-body-model').innerHTML = 'ARRAY OF:\n' + formatHintModel(
1020
+ args.action.codeHint.delegator.requestBody.items.fields,
1021
+ ).trim();
1018
1022
  } else {
1019
1023
  args.tabPage.querySelector('.request-body')?.remove();
1020
1024
  }
1025
+ console.log('args.action.codeHint.delegator', args.action.codeHint.delegator);
1026
+ if (args.action?.codeHint?.delegator?.result?.fields) {
1027
+ args.tabPage.querySelector('.response-body-model').innerHTML = formatHintModel(
1028
+ args.action.codeHint.delegator.result.fields,
1029
+ ).trim();
1030
+ } else if (args.action?.codeHint?.delegator?.result?.items?.fields) {
1031
+ args.tabPage.querySelector('.response-body-model').innerHTML = 'ARRAY OF:\n' + formatHintModel(
1032
+ args.action.codeHint.delegator.result.items.fields,
1033
+ ).trim();
1034
+ } else {
1035
+ args.tabPage.querySelector('.response-body')?.remove();
1036
+ }
1021
1037
  }
1022
1038
 
1023
1039
  function renderEntityView(entityName, viewName) {
@@ -1594,14 +1610,13 @@ window.codeSnippets = {
1594
1610
  rootUrlPath: args.rootUrlPath,
1595
1611
  entityName: args.entityName,
1596
1612
  httpMethod: getHttpMethod(args.actionName),
1597
- bodyDisplay: args.action?.codeHint?.delegator?.requestBody?.fields ? 'inline' : 'none',
1598
- noBodyDisplay: args.action?.codeHint?.delegator?.requestBody?.fields ? 'none' : 'inline',
1599
1613
  tokenDisplay: args.action.grant !== '*' ? 'inline' : 'none',
1600
1614
  }),
1601
1615
  cURL: (args) =>
1602
1616
  renderTemplate('template-codeSnippets-generalAction-cURL', {
1603
1617
  rootUrl: localStorage.selected_root_url,
1604
1618
  entityName: args.entityName,
1619
+ httpMethod: getHttpMethod(args.actionName),
1605
1620
  tokenDisplay: args.action.grant !== '*' ? 'inline' : 'none',
1606
1621
  }),
1607
1622
  Java: (args) =>
@@ -41,7 +41,7 @@ const entityFeatureWhitelist = ['vn_text'];
41
41
  const vnTextWhitelist = ['fields', 'channels'];
42
42
  const vnTextChannelWhitelist = ['fields', 'name'];
43
43
  const actionCodeHintWhitelist = ['delegator'];
44
- const actionCodeHintDelegatorWhitelist = ['param', 'requestBody'];
44
+ const actionCodeHintDelegatorWhitelist = ['param', 'requestBody', 'result'];
45
45
  const fieldsOnlyWhitelist = ['fields'];
46
46
  const viewWhitelist = ['grant', 'deny', 'description', 'parameters', 'emptyResult', 'codeHint'];
47
47
  const viewCodeHintWhitelist = ['output'];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mushroom-cli",
3
- "version": "1.2.0-alpha.20",
3
+ "version": "1.2.0-alpha.21",
4
4
  "description": "Mushroom CLI",
5
5
  "main": "dist/mr.js",
6
6
  "type": "module",