Compare commits

..

8 Commits

Author SHA1 Message Date
Rainer Killinger
c7cdb013e2 0.0.4 2021-12-16 16:14:16 +01:00
Rainer Killinger
5d38d6f180 refactor: update dependencies 2021-12-16 16:13:41 +01:00
Wieland Schöbl
92741d6613 Merge branch '15-filter-tags-override-inherited-type-tags' into 'master'
Resolve "Filter tags override inherited type tags"

Closes #15

See merge request openstapps/es-mapping-generator!4
2021-09-28 12:49:03 +00:00
Wieland Schöbl
f0401e1889 fix: filter tags override inherited type tags 2021-09-28 12:49:02 +00:00
Rainer Killinger
61b1fde0ec Merge branch 'renovate/all' into 'master'
refactor: update all

See merge request openstapps/es-mapping-generator!1
2021-08-12 07:57:15 +00:00
openstappsbot
58e6b19a70 refactor: update all 2021-08-11 13:07:47 +00:00
Wieland Schöbl
5bd8025d08 docs: fix readme badges 2021-08-05 19:53:16 +02:00
Wieland Schoebl
32c4cee4aa docs: update changelog 2021-08-05 19:41:13 +02:00
43 changed files with 492 additions and 720 deletions

View File

@@ -1,3 +1,12 @@
## [0.0.3](https://gitlab.com/openstapps/es-mapping-generator/compare/v0.0.2...v0.0.3) (2021-08-05)
### Bug Fixes
* put es template parsing ([9a88129](https://gitlab.com/openstapps/es-mapping-generator/commit/9a881299dc9d0a6d59b370340880a10bd8b1e2c5))
## [0.0.2](https://gitlab.com/openstapps/es-mapping-generator/compare/28334b800c014a9e0b6e980b5365af6fdc1d8950...v0.0.2) (2021-08-05)

View File

@@ -1,8 +1,8 @@
# @openstapps/es-mapping-generator
[![pipeline status](https://img.shields.io/gitlab/pipeline/openstapps/es-mapping-gen.svg?style=flat-square)](https://gitlab.com/openstapps/es-mapping-gen/commits/master)
[![npm](https://img.shields.io/npm/v/@openstapps/es-mapping-gen.svg?style=flat-square)](https://npmjs.com/package/@openstapps/es-mapping-gen)
[![license)](https://img.shields.io/npm/l/@openstapps/es-mapping-gen.svg?style=flat-square)](https://www.gnu.org/licenses/gpl-3.0.en.html)
[![pipeline status](https://img.shields.io/gitlab/pipeline/openstapps/es-mapping-generator.svg?style=flat-square)](https://gitlab.com/openstapps/es-mapping-gen/commits/master)
[![npm](https://img.shields.io/npm/v/@openstapps/es-mapping-generator.svg?style=flat-square)](https://npmjs.com/package/@openstapps/es-mapping-gen)
[![license)](https://img.shields.io/npm/l/@openstapps/es-mapping-generator.svg?style=flat-square)](https://www.gnu.org/licenses/gpl-3.0.en.html)
[![documentation](https://img.shields.io/badge/documentation-online-blue.svg?style=flat-square)](https://openstapps.gitlab.io/es-mapping-gen)
Tools to convert and validate StAppsCore

720
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -1,6 +1,6 @@
{
"name": "@openstapps/es-mapping-generator",
"version": "0.0.3",
"version": "0.0.4",
"description": "Tool to convert TypeScript Interfaces to Elasticsearch Mappings",
"license": "GPL-3.0-only",
"main": "./lib/index.js",
@@ -23,28 +23,28 @@
"tslint": "tslint -p tsconfig.json -c tslint.json 'src/**/*.ts'"
},
"dependencies": {
"@openstapps/logger": "0.7.0",
"commander": "8.1.0",
"@openstapps/logger": "0.8.0",
"commander": "8.3.0",
"deepmerge": "4.2.2",
"flatted": "3.2.2",
"got": "11.8.2",
"flatted": "3.2.4",
"got": "11.8.3",
"typedoc": "0.18.0",
"typescript": "3.8.3"
},
"devDependencies": {
"@openstapps/configuration": "0.27.0",
"@testdeck/mocha": "0.1.2",
"@types/chai": "4.2.21",
"@types/mocha": "8.2.3",
"@types/node": "14.17.5",
"@types/rimraf": "3.0.1",
"conventional-changelog-cli": "2.1.1",
"mocha": "9.0.2",
"@openstapps/configuration": "0.29.0",
"@testdeck/mocha": "0.2.0",
"@types/chai": "4.3.0",
"@types/mocha": "9.0.0",
"@types/node": "14.18.0",
"@types/rimraf": "3.0.2",
"chai": "4.3.4",
"nock": "13.1.1",
"conventional-changelog-cli": "2.1.1",
"mocha": "9.1.3",
"nock": "13.2.1",
"prepend-file-cli": "1.0.6",
"rimraf": "3.0.2",
"ts-node": "10.1.0",
"ts-node": "10.4.0",
"tslint": "6.1.3"
}
}

View File

@@ -67,4 +67,17 @@ export const typemap: ElasticsearchTypemap = {
},
};
/**
* If the string is a tag type
*/
export function isTagType(str: string): boolean {
for (const key in typemap) {
if (typemap.hasOwnProperty(key) && typeof typemap[key][str] !== 'undefined') {
return true;
}
}
return false;
}
export const dynamicTypes = ['any', 'unknown'];

View File

@@ -31,7 +31,7 @@ import {
import {fieldmap, filterableMap, filterableTagName} from './config/fieldmap';
import {premaps} from './config/premap';
import {settings} from './config/settings';
import {dynamicTypes, ElasticsearchDataType, typemap} from './config/typemap';
import {dynamicTypes, ElasticsearchDataType, isTagType, typemap} from './config/typemap';
import {AggregationSchema, ESNestedAggregation} from './types/aggregation';
import {
ElasticsearchDynamicTemplate,
@@ -275,7 +275,11 @@ function handleDeclarationReflection(decl: DeclarationReflection,
}
} else if (decl.type instanceof Type) { // if the object is a type, so we are dealing with a PROPERTY
// get inherited tags
const tags = (inheritedTags ?? []).length > 0 ? inheritedTags! : getCommentTags(decl, path, topTypeName);
const tags = (inheritedTags ?? []).length > 0
? (typeof inheritedTags!.find(it => isTagType(it.tagName)) !== 'undefined'
? inheritedTags!
: [...inheritedTags ?? [], ...getCommentTags(decl, path, topTypeName)])
: getCommentTags(decl, path, topTypeName);
return handleType(decl.type, new Map(generics), path, topTypeName, tags);
} else if (decl.kindString === 'Enumeration member') {

View File

@@ -13,59 +13,38 @@
* this program. If not, see <https://www.gnu.org/licenses/>.
*/
import {Logger} from '@openstapps/logger';
import {slow, suite, test, timeout} from '@testdeck/mocha';
import {readdirSync, statSync} from 'fs';
import path from 'path';
import {MapAggTest} from './mapping-model/MapAggTest';
import {aggArrayTest} from './mapping-model/aggregations/src/agg-array';
import {aggNestedTest} from './mapping-model/aggregations/src/agg-nested';
import {aggGlobalTest} from './mapping-model/aggregations/src/agg-global';
import {aggGlobalNestedTest} from './mapping-model/aggregations/src/agg-global-nested';
import {aggInheritedTest} from './mapping-model/aggregations/src/agg-inherited';
import {aggInheritedGlobalTest} from './mapping-model/aggregations/src/agg-inherited-global';
import {aggInheritedOverwrittenTest} from './mapping-model/aggregations/src/agg-inherited-overwritten';
import {MapAggTestOptions} from './mapping-model/MapAggTestOptions';
process.on('unhandledRejection', (error: unknown) => {
if (error instanceof Error) {
void Logger.error('UNHANDLED REJECTION', error.stack);
}
process.exit(1);
});
describe('ES Aggregation Gen', async () => {
const magAppInstance = new MapAggTest('aggregations');
const magAppInstance = new MapAggTest('aggregations');
/**
* Expand a path to a list of all files deeply contained in it
*/
function expandPathToFilesSync(sourcePath: string, accept: (fileName: string) => boolean): string[] {
const fullPath = path.resolve(sourcePath);
const directory = statSync(fullPath);
@suite(timeout(20000), slow(10000))
export class AggregationsSpec {
@test
async 'Aggregation tag should propagate on arrays'() {
magAppInstance.testInterfaceAgainstPath(aggArrayTest);
return directory.isDirectory()
? ([] as string[]).concat(...readdirSync(fullPath).map(fragment =>
expandPathToFilesSync(path.resolve(sourcePath, fragment), accept),
))
: [fullPath].filter(accept);
}
@test
async 'Should work on nested properties'() {
magAppInstance.testInterfaceAgainstPath(aggNestedTest);
}
for (const file of expandPathToFilesSync('./test/mapping-model/aggregations/', file => file.endsWith('agg-test.ts'))) {
try {
const test = (await import(file))['testConfig'] as MapAggTestOptions;
@test
async 'Global option should work'() {
magAppInstance.testInterfaceAgainstPath(aggGlobalTest);
it(test.testName, function () {
magAppInstance.testInterfaceAgainstPath(test);
});
} catch (error) {
await Logger.error('UNHANDLED REJECTION', error.stack);
process.exit(1);
}
}
@test
async 'Global aggregations when nested'() {
magAppInstance.testInterfaceAgainstPath(aggGlobalNestedTest);
}
@test
async 'Inherited aggregations should work'() {
magAppInstance.testInterfaceAgainstPath(aggInheritedTest);
}
@test
async 'Inherited global aggregations should work'() {
magAppInstance.testInterfaceAgainstPath(aggInheritedGlobalTest);
}
@test
async 'Inherited aggregations should work when overwritten'() {
magAppInstance.testInterfaceAgainstPath(aggInheritedOverwrittenTest);
}
}
}).timeout(20_000).slow(10_000);

View File

@@ -16,6 +16,7 @@
import {ElasticsearchDynamicTemplate, ElasticsearchValue} from '../../src/types/mapping';
export interface MapAggTestOptions {
testName: string;
name: string;
agg?: {
fields?: string[];

View File

@@ -29,7 +29,8 @@ export interface AggArray {
}
type Foo = 'A' | 'B' | 'C';
export const aggArrayTest: MapAggTestOptions = {
export const testConfig: MapAggTestOptions = {
testName: 'Aggregation tag should propagate on arrays',
name: ThingType.AggArray,
agg: {
fields: ['array'],

View File

@@ -30,7 +30,8 @@ export interface AggGlobalNested {
type: ThingType.AggGlobalNested;
}
export const aggGlobalNestedTest: MapAggTestOptions = {
export const testConfig: MapAggTestOptions = {
testName: 'Global aggregations when nested',
name: ThingType.AggGlobalNested,
agg: {
globals: ['foo'],

View File

@@ -28,7 +28,8 @@ export interface AggGlobal {
type: ThingType.AggGlobal;
}
export const aggGlobalTest: MapAggTestOptions = {
export const testConfig: MapAggTestOptions = {
testName: 'Global option should work',
name: ThingType.AggGlobal,
agg: {
globals: ['foo'],

View File

@@ -31,7 +31,8 @@ interface Foo {
bar: string;
}
export const aggInheritedGlobalTest: MapAggTestOptions = {
export const testConfig: MapAggTestOptions = {
testName: 'Inherited global aggregations should work',
name: ThingType.AggInheritedGlobal,
agg: {
globals: ['bar'],

View File

@@ -36,7 +36,8 @@ interface Foo {
bar: string;
}
export const aggInheritedOverwrittenTest: MapAggTestOptions = {
export const testConfig: MapAggTestOptions = {
testName: 'Inherited aggregations should work when overwritten',
name: ThingType.AggInherited,
agg: {
fields: ['bar'],

View File

@@ -31,7 +31,8 @@ interface Foo {
bar: string;
}
export const aggInheritedTest: MapAggTestOptions = {
export const testConfig: MapAggTestOptions = {
testName: 'Inherited aggregations should work',
name: ThingType.AggInherited,
agg: {
fields: ['bar'],

View File

@@ -30,7 +30,8 @@ export interface AggNested {
type: ThingType.AggNested;
}
export const aggNestedTest: MapAggTestOptions = {
export const testConfig: MapAggTestOptions = {
testName: 'Should work on nested properties',
name: ThingType.AggNested,
agg: {
fields: ['nested.foo'],

View File

@@ -27,7 +27,8 @@ export interface AnyUnknown {
type: ThingType.AnyUnknown
}
export const anyUnknownTest: MapAggTestOptions = {
export const testConfig: MapAggTestOptions = {
testName: 'Any or unknown should create a dynamic field',
name: ThingType.AnyUnknown,
map: {
maps: {

View File

@@ -36,7 +36,8 @@ export interface DateAndRange {
type: ThingType.Date
}
export const dateAndRangeTest: MapAggTestOptions = {
export const testConfig: MapAggTestOptions = {
testName: 'Dates and date ranges should have the correct type',
name: ThingType.Date,
map: {
maps: {

View File

@@ -30,7 +30,8 @@ interface InterfaceWithDefaultGeneric<T = number> {
bar: T;
}
export const defaultGenericTest: MapAggTestOptions = {
export const testConfig: MapAggTestOptions = {
testName: 'Default generics should fail',
name: ThingType.DefaultGeneric,
map: {
maps: {

View File

@@ -36,7 +36,8 @@ export interface DoubleTypeConflict {
type: ThingType.DoubleTypeConflict;
}
export const doubleTypeConflictTest: MapAggTestOptions = {
export const testConfig: MapAggTestOptions = {
testName: 'Double type annotations should cause an error',
name: ThingType.DoubleTypeConflict,
map: {
maps: {

View File

@@ -40,7 +40,10 @@ enum Baz {
f = 'f',
}
export const enumTest: MapAggTestOptions = {
export const testConfig: MapAggTestOptions = {
// Known issue: Enums only use text
// https://gitlab.com/openstapps/core-tools/-/issues/46
testName: 'Emums should work',
name: ThingType.Enum,
map: {
maps: {

View File

@@ -48,7 +48,8 @@ export interface FilterableTag {
type: ThingType.FilterableTag
}
export const filterableTagTest: MapAggTestOptions = {
export const testConfig: MapAggTestOptions = {
testName: 'Filterable tag should add raw field to strings',
name: ThingType.FilterableTag,
map: {
maps: {

View File

@@ -35,7 +35,8 @@ interface InterfaceWithStringGeneric<T> {
bar: T;
}
export const genericTest: MapAggTestOptions = {
export const testConfig: MapAggTestOptions = {
testName: 'Generics should work',
name: ThingType.Generics,
map: {
maps: {

View File

@@ -26,7 +26,8 @@ export interface ImpossibleUnion {
type: ThingType.ImpossibleUnion
}
export const impossibleUnionTest: MapAggTestOptions = {
export const testConfig: MapAggTestOptions = {
testName: 'Impossible union should cause an error',
name: ThingType.ImpossibleUnion,
map: {
maps: {

View File

@@ -45,7 +45,8 @@ export interface DoubleTypeConflict {
type: ThingType.IncompatibleType;
}
export const incompatibleTypeTest: MapAggTestOptions = {
export const testConfig: MapAggTestOptions = {
testName: 'Incompatible type annotations should cause an error and use defaults',
name: ThingType.IncompatibleType,
map: {
maps: {

View File

@@ -31,7 +31,8 @@ export interface IndexSignature {
type: ThingType.IndexSignature;
}
export const indexSignatureTest: MapAggTestOptions = {
export const testConfig: MapAggTestOptions = {
testName: 'Index Signatures should work',
name: ThingType.IndexSignature,
map: {
maps: {

View File

@@ -0,0 +1,60 @@
/*
* Copyright (C) 2020 StApps
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* 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 {ElasticsearchDataType} from '../../../../src/config/typemap';
import {MapAggTestOptions} from '../../MapAggTestOptions';
import {ThingType} from './types';
/**
* @date
*/
export type SCISO8601Date = string;
/**
* @indexable
*/
export interface InferredTypeFilterable {
/**
* @filterable
*/
foo: SCISO8601Date;
/**
* // no tag
*/
bar: SCISO8601Date;
type: ThingType.InferredTypeFilterable
}
export const testConfig: MapAggTestOptions = {
testName: 'filterable tags should not override inferred tags',
name: ThingType.InferredTypeFilterable,
map: {
maps: {
foo: {
type: ElasticsearchDataType.date,
fields: {
raw: {
type: ElasticsearchDataType.keyword,
}
}
},
bar: {
type: ElasticsearchDataType.date,
}
}
}
};

View File

@@ -36,7 +36,8 @@ export interface InheritTags {
type: ThingType.InheritTags;
}
export const inheritTagsTest: MapAggTestOptions = {
export const testConfig: MapAggTestOptions = {
testName: 'Inherit tags tag should work',
name: ThingType.InheritTags,
map: {
maps: {

View File

@@ -38,7 +38,8 @@ interface Bar {
baz: number;
}
export const inheritedPropertyTest: MapAggTestOptions = {
export const testConfig: MapAggTestOptions = {
testName: 'Inherited properties should inherit tags',
name: ThingType.InheritedProperty,
map: {
maps: {

View File

@@ -29,7 +29,8 @@ export interface InvalidTag {
type: ThingType.InvalidTag;
}
export const invalidTagTest: MapAggTestOptions = {
export const testConfig: MapAggTestOptions = {
testName: 'Invalid tags should cause an error',
name: ThingType.InvalidTag,
map: {
maps: {

View File

@@ -54,7 +54,8 @@ export interface MapExplicitTypes {
type: ThingType.MapExplicitTypes;
}
export const mapExplicitTypesTest: MapAggTestOptions = {
export const testConfig: MapAggTestOptions = {
testName: 'Explicit type annotations should work',
name: ThingType.MapExplicitTypes,
map: {
maps: {

View File

@@ -29,7 +29,8 @@ export interface MissingPremap {
type: ThingType.MissingPremap;
}
export const missingPremapTest: MapAggTestOptions = {
export const testConfig: MapAggTestOptions = {
testName: 'Missing premap should cause an error',
name: ThingType.MissingPremap,
map: {
maps: {

View File

@@ -37,7 +37,8 @@ export interface Nested {
type: ThingType.Nested;
}
export const nestedTest: MapAggTestOptions = {
export const testConfig: MapAggTestOptions = {
testName: 'Nested properties should work',
name: ThingType.Nested,
map: {
maps: {

View File

@@ -40,7 +40,8 @@ interface Buu {
intersection: string;
}
export const objectUnionTest: MapAggTestOptions = {
export const testConfig: MapAggTestOptions = {
testName: 'Object union types should work',
name: ThingType.ObjectUnion,
map: {
maps: {

View File

@@ -37,7 +37,8 @@ export interface PairedTags {
type: ThingType.PairedTags;
}
export const pairedTagsTest: MapAggTestOptions = {
export const testConfig: MapAggTestOptions = {
testName: 'Tags should be able to be paired',
name: ThingType.PairedTags,
map: {
maps: {

View File

@@ -31,7 +31,8 @@ export interface SensibleDefaults {
type: ThingType.SensibleDefaultType;
}
export const sensibleDefaultsTest: MapAggTestOptions = {
export const testConfig: MapAggTestOptions = {
testName: 'Primitive types should have sensible defaults',
name: ThingType.SensibleDefaultType,
map: {
maps: {

View File

@@ -39,7 +39,8 @@ export interface SortableTag {
type: ThingType.SortableTag
}
export const sortableTagTest: MapAggTestOptions = {
export const testConfig: MapAggTestOptions = {
testName: 'Sortable tag should work',
name: ThingType.SortableTag,
map: {
maps: {

View File

@@ -40,7 +40,8 @@ export interface TagsIgnoreCase {
type: ThingType.TagsIgnoreCase;
}
export const tagsIgnoreCaseTest: MapAggTestOptions = {
export const testConfig: MapAggTestOptions = {
testName: 'Tags should ignore case',
name: ThingType.TagsIgnoreCase,
map: {
maps: {

View File

@@ -49,7 +49,8 @@ type ATextAlias = string;
*/
type AKeywordAlias = string;
export const typeAliasTest: MapAggTestOptions = {
export const testConfig: MapAggTestOptions = {
testName: 'Type alias annotations should work',
name: ThingType.TypeAlias,
map: {
maps: {

View File

@@ -30,7 +30,8 @@ export interface TypeOverrides {
type: ThingType.TypeOverrides
}
export const typeOverridesTest: MapAggTestOptions = {
export const testConfig: MapAggTestOptions = {
testName: 'Premaps should support non-external types',
name: ThingType.TypeOverrides,
map: {
maps: {

View File

@@ -32,7 +32,9 @@ enum Bar {
'c'
}
export const typeQueryTest: MapAggTestOptions = {
// https://gitlab.com/openstapps/core-tools/-/issues/47
export const testConfig: MapAggTestOptions = {
testName: 'Type queries should work',
name: ThingType.TypeQuery,
map: {
maps: {

View File

@@ -43,7 +43,9 @@ type NumberWrapper = number;
type StringWrapper = string;
type StringLiteralWrapper = 'foo';
export const typeWrapperInheritanceTest: MapAggTestOptions = {
// https://gitlab.com/openstapps/core-tools/-/merge_requests/29
export const testConfig: MapAggTestOptions = {
testName: 'Wrapper types should inherit tags',
name: ThingType.TypeWrapperInheritance,
map: {
maps: {

View File

@@ -34,6 +34,7 @@ export enum ThingType {
PairedTags = 'paired tags',
FilterableTag = 'filterable tag',
AnyUnknown = 'any unknown',
InferredTypeFilterable = 'inferred type filterable',
Date = 'date',
InheritTags = 'inherit tags',
TagsIgnoreCase = 'tags ignore case',

View File

@@ -13,171 +13,38 @@
* this program. If not, see <https://www.gnu.org/licenses/>.
*/
import {Logger} from '@openstapps/logger';
import {slow, suite, test, timeout} from '@testdeck/mocha';
import {readdirSync, statSync} from 'fs';
import path from 'path';
import {MapAggTest} from './mapping-model/MapAggTest';
import {inheritTagsTest} from './mapping-model/mappings/src/inherit-tags';
import {mapExplicitTypesTest} from './mapping-model/mappings/src/map-explicit-types';
import {doubleTypeConflictTest} from './mapping-model/mappings/src/double-type-conflict';
import {incompatibleTypeTest} from './mapping-model/mappings/src/incompatible-type';
import {sensibleDefaultsTest} from './mapping-model/mappings/src/sensible-defaults';
import {invalidTagTest} from './mapping-model/mappings/src/invalid-tag';
import {missingPremapTest} from './mapping-model/mappings/src/missing-premap';
import {defaultGenericTest} from './mapping-model/mappings/src/default-generics';
import {genericTest} from './mapping-model/mappings/src/generics';
import {nestedTest} from './mapping-model/mappings/src/nested';
import {indexSignatureTest} from './mapping-model/mappings/src/index-signature';
import {impossibleUnionTest} from './mapping-model/mappings/src/impossible-union';
import {objectUnionTest} from './mapping-model/mappings/src/object-union';
import {sortableTagTest} from './mapping-model/mappings/src/sortable-tag';
import {enumTest} from './mapping-model/mappings/src/enum';
import {inheritedPropertyTest} from './mapping-model/mappings/src/inherited-property';
import {pairedTagsTest} from './mapping-model/mappings/src/paired-tags';
import {filterableTagTest} from './mapping-model/mappings/src/filterable-tag';
import {anyUnknownTest} from './mapping-model/mappings/src/any-unknown';
import {tagsIgnoreCaseTest} from './mapping-model/mappings/src/tags-ignore-case';
import {typeAliasTest} from './mapping-model/mappings/src/type-alias';
import {dateAndRangeTest} from './mapping-model/mappings/src/date';
import {typeOverridesTest} from './mapping-model/mappings/src/type-overrides';
import {MapAggTestOptions} from './mapping-model/MapAggTestOptions';
process.on('unhandledRejection', (error: unknown) => {
if (error instanceof Error) {
void Logger.error('UNHANDLED REJECTION', error.stack);
}
process.exit(1);
});
describe('ES Mapping Gen', async () => {
const magAppInstance = new MapAggTest('mappings');
const magAppInstance = new MapAggTest('mappings');
/**
* Expand a path to a list of all files deeply contained in it
*/
function expandPathToFilesSync(sourcePath: string, accept: (fileName: string) => boolean): string[] {
const fullPath = path.resolve(sourcePath);
const directory = statSync(fullPath);
@suite(timeout(20000), slow(10000))
export class MappingSpec {
@test
async 'Any or unknown should create a dynamic field'() {
magAppInstance.testInterfaceAgainstPath(anyUnknownTest);
return directory.isDirectory()
? ([] as string[]).concat(...readdirSync(fullPath).map(fragment =>
expandPathToFilesSync(path.resolve(sourcePath, fragment), accept),
))
: [fullPath].filter(accept);
}
@test
async 'Filterable tag should add raw field to strings'() {
magAppInstance.testInterfaceAgainstPath(filterableTagTest);
for (const file of expandPathToFilesSync('./test/mapping-model/mappings/', file => file.endsWith('mapping-test.ts'))) {
try {
const test = (await import(file))['testConfig'] as MapAggTestOptions;
it(test.testName, function () {
magAppInstance.testInterfaceAgainstPath(test)
})
} catch (error) {
await Logger.error('UNHANDLED REJECTION', error.stack);
process.exit(1);
}
}
@test
async 'Tags should be able to be paired'() {
magAppInstance.testInterfaceAgainstPath(pairedTagsTest);
}
@test
async 'Inherited properties should inherit tags'() {
magAppInstance.testInterfaceAgainstPath(inheritedPropertyTest);
}
@test
async 'Tags should ignore case'() {
magAppInstance.testInterfaceAgainstPath(tagsIgnoreCaseTest);
}
@test
async 'Emums should work'() {
// Known issue: Enums only use text
// https://gitlab.com/openstapps/core-tools/-/issues/46
magAppInstance.testInterfaceAgainstPath(enumTest);
}
@test
async 'Sortable tag should work'() {
magAppInstance.testInterfaceAgainstPath(sortableTagTest);
}
/*
https://gitlab.com/openstapps/core-tools/-/merge_requests/29
@test
async 'Wrapper types should inherit tags'() {
this.testInterfaceAgainstPath(typeWrapperInheritanceTest);
}*/
@test
async 'Inherit tags tag should work'() {
magAppInstance.testInterfaceAgainstPath(inheritTagsTest);
}
@test
async 'Object union types should work'() {
magAppInstance.testInterfaceAgainstPath(objectUnionTest);
}
/*
https://gitlab.com/openstapps/core-tools/-/issues/47
@test
async 'Type queries should work'() {
magAppInstance.testInterfaceAgainstPath(typeQueryTest);
}*/
@test
async 'Type alias annotations should work'(){
magAppInstance.testInterfaceAgainstPath(typeAliasTest);
}
@test
async 'Impossible union should cause an error'() {
magAppInstance.testInterfaceAgainstPath(impossibleUnionTest);
}
@test
async 'Index Signatures should work'() {
magAppInstance.testInterfaceAgainstPath(indexSignatureTest);
}
@test
async 'Nested properties should work'() {
magAppInstance.testInterfaceAgainstPath(nestedTest);
}
@test
async 'Generics should work'() {
magAppInstance.testInterfaceAgainstPath(genericTest);
}
@test
async 'Missing premap should cause an error'() {
magAppInstance.testInterfaceAgainstPath(missingPremapTest);
}
@test
async 'Default generics should fail'() {
magAppInstance.testInterfaceAgainstPath(defaultGenericTest);
}
@test
async 'Explicit type annotations should work'() {
magAppInstance.testInterfaceAgainstPath(mapExplicitTypesTest);
}
@test
async 'Double type annotations should cause an error'() {
magAppInstance.testInterfaceAgainstPath(doubleTypeConflictTest);
}
@test
async 'Incompatible type annotations should cause an error and use defaults'() {
magAppInstance.testInterfaceAgainstPath(incompatibleTypeTest);
}
@test
async 'Primitive types should have sensible defaults'() {
magAppInstance.testInterfaceAgainstPath(sensibleDefaultsTest);
}
@test
async 'Invalid tags should cause an error'() {
magAppInstance.testInterfaceAgainstPath(invalidTagTest);
}
@test
async 'Dates and date ranges should have the correct type'() {
magAppInstance.testInterfaceAgainstPath(dateAndRangeTest);
}
@test
async 'Premaps should support non-external types'() {
magAppInstance.testInterfaceAgainstPath(typeOverridesTest);
}
}
}).timeout(20_000).slow(10_000);