mirror of
https://gitlab.com/openstapps/openstapps.git
synced 2026-01-01 11:02:49 +00:00
Compare commits
8 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c7cdb013e2 | ||
|
|
5d38d6f180 | ||
|
|
92741d6613 | ||
|
|
f0401e1889 | ||
|
|
61b1fde0ec | ||
|
|
58e6b19a70 | ||
|
|
5bd8025d08 | ||
|
|
32c4cee4aa |
@@ -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)
|
||||
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
# @openstapps/es-mapping-generator
|
||||
|
||||
[](https://gitlab.com/openstapps/es-mapping-gen/commits/master)
|
||||
[](https://npmjs.com/package/@openstapps/es-mapping-gen)
|
||||
[](https://www.gnu.org/licenses/gpl-3.0.en.html)
|
||||
[](https://gitlab.com/openstapps/es-mapping-gen/commits/master)
|
||||
[](https://npmjs.com/package/@openstapps/es-mapping-gen)
|
||||
[](https://www.gnu.org/licenses/gpl-3.0.en.html)
|
||||
[](https://openstapps.gitlab.io/es-mapping-gen)
|
||||
|
||||
Tools to convert and validate StAppsCore
|
||||
|
||||
720
package-lock.json
generated
720
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
30
package.json
30
package.json
@@ -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"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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'];
|
||||
|
||||
@@ -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') {
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
import {ElasticsearchDynamicTemplate, ElasticsearchValue} from '../../src/types/mapping';
|
||||
|
||||
export interface MapAggTestOptions {
|
||||
testName: string;
|
||||
name: string;
|
||||
agg?: {
|
||||
fields?: string[];
|
||||
|
||||
@@ -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'],
|
||||
@@ -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'],
|
||||
@@ -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'],
|
||||
@@ -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'],
|
||||
@@ -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'],
|
||||
@@ -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'],
|
||||
@@ -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'],
|
||||
@@ -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: {
|
||||
@@ -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: {
|
||||
@@ -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: {
|
||||
@@ -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: {
|
||||
@@ -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: {
|
||||
@@ -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: {
|
||||
@@ -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: {
|
||||
@@ -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: {
|
||||
@@ -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: {
|
||||
@@ -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: {
|
||||
@@ -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,
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -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: {
|
||||
@@ -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: {
|
||||
@@ -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: {
|
||||
@@ -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: {
|
||||
@@ -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: {
|
||||
@@ -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: {
|
||||
@@ -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: {
|
||||
@@ -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: {
|
||||
@@ -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: {
|
||||
@@ -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: {
|
||||
@@ -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: {
|
||||
@@ -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: {
|
||||
@@ -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: {
|
||||
@@ -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: {
|
||||
@@ -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: {
|
||||
@@ -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',
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user