feat: add elasticsearch mappings to build

Add backwards compatibility check with typescript v3.8.3
This commit is contained in:
Wieland Schöbl
2021-08-12 13:09:45 +00:00
committed by Jovan Krunić
parent 2dfb64bafd
commit 21eeecd5ee
5 changed files with 279 additions and 47 deletions

View File

@@ -12,21 +12,55 @@
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <https://www.gnu.org/licenses/>.
*/
import {getProjectReflection} from '@openstapps/core-tools/lib/common';
import {getTsconfigPath} from '@openstapps/core-tools/lib/common';
import {validateFiles, writeReport} from '@openstapps/core-tools/lib/validate';
import {Logger} from '@openstapps/logger';
import {fail} from 'assert';
import {expect} from 'chai';
import {mkdirSync} from 'fs';
import {mkdirSync, PathLike} from 'fs';
import {slow, suite, test, timeout} from '@testdeck/mocha';
import {join, resolve} from 'path';
import {DeclarationReflection, ProjectReflection} from 'typedoc';
import {ArrayType, IntrinsicType, ReferenceType, StringLiteralType, Type, UnionType} from 'typedoc/dist/lib/models';
import {Application, DeclarationReflection, ProjectReflection, TSConfigReader} from 'typedoc';
import {ArrayType, IntrinsicType, ReferenceType, LiteralType, Type, UnionType} from 'typedoc/dist/lib/models';
process.on('unhandledRejection', (err) => {
throw err;
});
/**
* Get a project reflection from a path
*
* @param srcPath Path to get reflection from
* @param excludeExternals Exclude external dependencies
*/
export function getProjectReflection(srcPath: PathLike, excludeExternals = true): ProjectReflection {
Logger.info(`Generating project reflection for ${srcPath.toString()}.`);
const tsconfigPath = getTsconfigPath(srcPath.toString());
let inputFilePath = srcPath;
if (inputFilePath === tsconfigPath) {
inputFilePath = join(tsconfigPath, 'src');
}
// initialize new Typedoc application
const app = new Application();
app.options.addReader(new TSConfigReader());
app.bootstrap({
entryPoints: [inputFilePath.toString()],
excludeExternals: excludeExternals,
tsconfig: join(tsconfigPath, 'tsconfig.json'),
});
// get project reflection from input files
const result = app.convert();
if (typeof result === 'undefined') {
throw new Error('Project reflection could not be generated.');
}
return result;
}
/**
* Check if type is a union type
*
@@ -68,8 +102,8 @@ function isIntrinsicType(type: Type): type is IntrinsicType {
*
* @param type Type to check
*/
function isStringLiteralType(type: Type): type is StringLiteralType {
return type.type === 'stringLiteral';
function isLiteralType(type: Type): type is LiteralType {
return type.type === 'literal';
}
/**
@@ -182,6 +216,22 @@ export class SchemaSpec {
@test
'no property is an SCThing'() {
const handleUnionType = (type: UnionType, thingName: string, property: DeclarationReflection) => {
for (const nestedType of type.types) {
if (isIntrinsicType(nestedType) || isLiteralType(nestedType)) {
continue;
} else if (isReferenceType(nestedType)) {
expect(SchemaSpec.thingNames).not.to.contain(
nestedType.name,
`Union property '${property.name}' on type '${thingName}' contains type '${nestedType.name}'.`,
);
} else {
// tslint:disable-next-line:max-line-length
fail(`'${thingName}'#'${property.name}' union type '${nestedType.type}' is not handled by this test!`);
}
}
}
for (const thingName of SchemaSpec.thingNames) {
const thingReflection = SchemaSpec.objects[`${thingName}`];
@@ -199,8 +249,10 @@ export class SchemaSpec {
} else if (isArrayType(type)) {
const elementType = type.elementType;
if (isIntrinsicType(elementType)) {
if (isIntrinsicType(elementType) || isLiteralType(elementType)) {
continue;
} else if (isUnionType(elementType)) {
handleUnionType(elementType, thingName, property);
} else if (isReferenceType(elementType)) {
expect(SchemaSpec.thingNames).not.to.contain(
elementType.name,
@@ -230,19 +282,7 @@ export class SchemaSpec {
}
} while (isReferenceType(type));
} else if (isUnionType(type)) {
for (const nestedType of type.types) {
if (isIntrinsicType(nestedType) || isStringLiteralType(nestedType)) {
continue;
} else if (isReferenceType(nestedType)) {
expect(SchemaSpec.thingNames).not.to.contain(
nestedType.name,
`Union property '${property.name}' on type '${thingName}' contains type '${nestedType.name}'.`,
);
} else {
// tslint:disable-next-line:max-line-length
fail(`'${thingName}'#'${property.name}' union type '${nestedType.type}' is not handled by this test!`);
}
}
handleUnionType(type, thingName, property);
} else {
// tslint:disable-next-line:max-line-length
fail(`'${thingName}'#'${property.name}' with type '${type.type}' is not handled by this test!`);