Skip to content

Commit 70015f5

Browse files
authored
fix(cubejs-client-core): table pivot (#672)
* fix(cubejs-client-core): table pivot * tablePivot tests * test: fix * fix: tablePivot, tests * fix: tableColumns, tests * fix: fromEntries replacement * docs: tablePivot, tableColumns * feat(docs-gen): typeDefs support
1 parent ce7cfc1 commit 70015f5

File tree

16 files changed

+4726
-4833
lines changed

16 files changed

+4726
-4833
lines changed

.eslintrc.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ module.exports = {
2929
ignoreTemplateLiterals: true,
3030
}],
3131
'no-trailing-spaces': ['error', { skipBlankLines: true }],
32-
'no-unused-vars': ['warn']
32+
'no-unused-vars': ['warn'],
33+
'object-curly-newline': 0
3334
}
3435
};

.prettierrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"semi": true,
66
"singleQuote": true,
77
"arrowParens": "always",
8-
"trailingComma": "none",
8+
"trailingComma": "es5",
99
"bracketSpacing": true,
1010
"jsxBracketSameLine": false,
1111
"overrides": [

docs-gen/template/publish.js

Lines changed: 58 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@ const fs = require('fs-extra');
22
const inline = require('jsdoc/tag/inline');
33
const inflection = require('inflection');
44

5+
let typeDefs = [];
56
let knownClassNames = [];
67

8+
79
const anchorName = (link) => inflection.dasherize(inflection.underscore(link.replace(/#/g, '-')));
810

9-
const resolveInlineLinks = str => {
10-
return inline.replaceInlineTags(str, {
11-
link: (string, { completeTag, text, tag }) => string.replace(completeTag, `[${text}](#${anchorName(text)})`)
12-
}).newString;
13-
};
11+
const resolveInlineLinks = str => inline.replaceInlineTags(str, {
12+
link: (string, { completeTag, text }) => string.replace(completeTag, `[${text}](#${anchorName(text)})`)
13+
}).newString;
1414

1515
const renderLinks = (p) => {
1616
if (p.type.names[0] === '*') {
@@ -28,22 +28,62 @@ const renderLinks = (p) => {
2828
function generateParams(doclet) {
2929
const params = doclet.params.map(
3030
p => {
31-
const optional = p.optional ? `**Optional**` : null;
31+
const optional = p.optional ? '**Optional**' : null;
3232
const defaultValue = p.defaultvalue ? `**Default:** \`${p.defaultvalue}\`` : null;
3333
const options = [optional, defaultValue].filter(f => !!f);
34+
35+
const type = p.type && p.type.parsedType.name;
36+
if (!p.description && typeDefs.find((td) => td.name === type)) {
37+
const [, parent] = doclet.memberof.split('~');
38+
p.description = `See {@link ${parent}#${type}}`;
39+
}
40+
3441
return `- \`${p.name}\`${options.length ? ` (${options.join(', ')})` : ''}${p.description ? ` - ${resolveInlineLinks(p.description)}` : ''}`;
3542
}
3643
);
3744
return `**Parameters:**\n\n${params.join('\n')}\n`;
3845
}
3946

47+
function generateTypeDefs(doclets) {
48+
let markDown = '';
49+
let codeBlock = [];
50+
let properties = [];
51+
52+
if (!doclets.length) {
53+
return '';
54+
}
55+
56+
doclets.forEach((doclet) => {
57+
markDown += [`**${doclet.name}**`, doclet.description].filter((d) => !!d).join('\n');
58+
doclet.properties.forEach((p) => {
59+
if (p.description) {
60+
properties.push(` // ${p.description.replace(/\n/g, '\n // ')}`);
61+
}
62+
63+
properties.push(` ${p.name}${p.optional ? '?' : ''}: ${p.type.parsedType.typeExpression}${p.defaultvalue ? ' = '.concat(p.defaultvalue) : ''}`);
64+
});
65+
66+
if (properties.length) {
67+
codeBlock.push('```js\n{');
68+
codeBlock.push(...properties);
69+
codeBlock.push('}\n```\n');
70+
}
71+
72+
markDown += `\n${codeBlock.join('\n')}`;
73+
properties = [];
74+
codeBlock = [];
75+
});
76+
77+
return `### Type definitions\n ${markDown}`;
78+
}
79+
4080
const generateFunctionDocletSection = (doclet, isConstructor) => {
4181
const title = doclet.name;
4282
const header = `##${doclet.longname.indexOf('#') !== -1 || isConstructor ? '#' : ''} ${title}${isConstructor ? ' Constructor' : ''}\n`;
43-
const args = doclet.params && doclet.params.filter(p => p.name.indexOf('.') === -1).map(p => p.optional ? `[${p.name}]` : p.name).join(', ') || '';
83+
const args = doclet.params && doclet.params.filter(p => p.name.indexOf('.') === -1).map(p => (p.optional ? `[${p.name}]` : p.name)).join(', ') || '';
4484
const signature = `\`${isConstructor ? 'new ' : ''}${doclet.meta.code.name || doclet.name}(${args})\`\n`;
45-
const params = doclet.params ? generateParams(doclet) : ``;
46-
const returns = doclet.returns ? `**Returns:** ${doclet.returns.map(p => `${p.type ? renderLinks(p) : ''}${p.description ? ` ${resolveInlineLinks(p.description)}` : ''}`)}` : ``;
85+
const params = doclet.params ? generateParams(doclet) : '';
86+
const returns = doclet.returns ? `**Returns:** ${doclet.returns.map(p => `${p.type ? renderLinks(p) : ''}${p.description ? ` ${resolveInlineLinks(p.description)}` : ''}`)}` : '';
4787
return [header, signature, doclet.description && `${resolveInlineLinks(doclet.description)}\n`, params, returns, '\n'].filter(f => !!f).join('\n');
4888
};
4989

@@ -83,20 +123,24 @@ const generateMarkDown = (doclets, parent) => {
83123
children.sort((a, b) => order(a) - order(b));
84124
return children.map(child => {
85125
if (child.kind === 'class') {
86-
return generateClassSection(child).concat(generateMarkDown(doclets, child));
126+
return generateClassSection(child)
127+
.concat(generateMarkDown(doclets, child))
128+
.concat(generateTypeDefs(typeDefs.filter((td) => td.memberof === child.name)));
87129
} else if (child.kind === 'function' || child.kind === 'member') {
88130
return generateFunctionDocletSection(child);
89131
}
90132
return null;
91133
}).filter(markdown => !!markdown).join('');
92134
};
93135

94-
const classNamesFrom = (doclets) => {
95-
return doclets.filter(d => d.kind === 'class').map(d => d.name);
96-
};
136+
const classNamesFrom = (doclets) => doclets.filter(d => d.kind === 'class').map(d => d.name);
97137

98138
exports.publish = (data, { destination }) => {
99139
knownClassNames = classNamesFrom(data().get());
100-
const markDown = generateMarkDown(data().get().filter(d => !d.undocumented));
140+
typeDefs = data().get().filter(d => d.kind === 'typedef');
141+
142+
const markDown = generateMarkDown(data().get().filter(d => {
143+
return !d.undocumented && d.kind !== 'typedef';
144+
}));
101145
fs.writeFile(destination, markDown);
102146
};

0 commit comments

Comments
 (0)