refactor: move es-mapping-generator to monorepo

This commit is contained in:
2023-05-24 13:23:12 +02:00
parent e0e803fba0
commit e76ffe9371
65 changed files with 0 additions and 0 deletions

View File

@@ -0,0 +1,59 @@
/* eslint-disable unicorn/consistent-function-scoping */
/*
* 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 {Logger} from '@openstapps/logger';
import {readdirSync, statSync} from 'fs';
import path from 'path';
import {MapAggTest} from './mapping-model/map-agg-test';
import {MapAggTestOptions} from './mapping-model/map-agg-test-options';
describe('ES Aggregation Gen', async () => {
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);
return directory.isDirectory()
? // eslint-disable-next-line unicorn/prefer-spread
([] as string[]).concat(
...readdirSync(fullPath).map(fragment =>
expandPathToFilesSync(path.resolve(sourcePath, fragment), accept),
),
)
: [fullPath].filter(accept);
}
for (const file of expandPathToFilesSync('./test/mapping-model/aggregations/', file =>
file.endsWith('agg-test.ts'),
)) {
try {
// eslint-disable-next-line unicorn/no-await-expression-member
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);
}
}
})
.timeout(20_000)
.slow(10_000);

View File

@@ -0,0 +1,38 @@
/*
* 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 {ThingType} from './types';
import {MapAggTestOptions} from '../../map-agg-test-options';
/**
* @indexable
*/
export interface AggArray {
/**
* @aggregatable
*/
array: Foo[];
type: ThingType.AggArray;
}
type Foo = 'A' | 'B' | 'C';
export const testConfig: MapAggTestOptions = {
testName: 'Aggregation tag should propagate on arrays',
name: ThingType.AggArray,
agg: {
fields: ['array'],
},
};

View File

@@ -0,0 +1,39 @@
/*
* 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 {ThingType} from './types';
import {MapAggTestOptions} from '../../map-agg-test-options';
/**
* @indexable
*/
export interface AggGlobalNested {
nested: {
/**
* @aggregatable global
*/
foo: string;
};
type: ThingType.AggGlobalNested;
}
export const testConfig: MapAggTestOptions = {
testName: 'Global aggregations when nested',
name: ThingType.AggGlobalNested,
agg: {
globals: ['foo'],
},
};

View File

@@ -0,0 +1,37 @@
/*
* 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 {ThingType} from './types';
import {MapAggTestOptions} from '../../map-agg-test-options';
/**
* @indexable
*/
export interface AggGlobal {
/**
* @aggregatable global
*/
foo: string;
type: ThingType.AggGlobal;
}
export const testConfig: MapAggTestOptions = {
testName: 'Global option should work',
name: ThingType.AggGlobal,
agg: {
globals: ['foo'],
},
};

View File

@@ -0,0 +1,39 @@
/*
* 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 {ThingType} from './types';
import {MapAggTestOptions} from '../../map-agg-test-options';
/**
* @indexable
*/
export interface AggInheritedGlobal extends Foo {
type: ThingType.AggInheritedGlobal;
}
interface Foo {
/**
* @aggregatable global
*/
bar: string;
}
export const testConfig: MapAggTestOptions = {
testName: 'Inherited global aggregations should work',
name: ThingType.AggInheritedGlobal,
agg: {
globals: ['bar'],
},
};

View File

@@ -0,0 +1,44 @@
/*
* 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 {ThingType} from './types';
import {MapAggTestOptions} from '../../map-agg-test-options';
/**
* @indexable
*/
export interface AggInherited extends Foo {
/**
* No tag here :)
*/
bar: 'some thing';
type: ThingType.AggInheritedOverwritten;
}
interface Foo {
/**
* @aggregatable
*/
bar: string;
}
export const testConfig: MapAggTestOptions = {
testName: 'Inherited aggregations should work when overwritten',
name: ThingType.AggInherited,
agg: {
fields: ['bar'],
},
};

View File

@@ -0,0 +1,39 @@
/*
* 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 {ThingType} from './types';
import {MapAggTestOptions} from '../../map-agg-test-options';
/**
* @indexable
*/
export interface AggInherited extends Foo {
type: ThingType.AggInherited;
}
interface Foo {
/**
* @aggregatable
*/
bar: string;
}
export const testConfig: MapAggTestOptions = {
testName: 'Inherited aggregations should work',
name: ThingType.AggInherited,
agg: {
fields: ['bar'],
},
};

View File

@@ -0,0 +1,39 @@
/*
* 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 {ThingType} from './types';
import {MapAggTestOptions} from '../../map-agg-test-options';
/**
* @indexable
*/
export interface AggNested {
nested: {
/**
* @aggregatable
*/
foo: string;
};
type: ThingType.AggNested;
}
export const testConfig: MapAggTestOptions = {
testName: 'Should work on nested properties',
name: ThingType.AggNested,
agg: {
fields: ['nested.foo'],
},
};

View File

@@ -0,0 +1,24 @@
/*
* 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/>.
*/
export enum ThingType {
AggArray = 'agg array',
AggGlobal = 'agg global',
AggGlobalNested = 'agg global nested',
AggNested = 'agg nested',
AggInherited = 'agg inherited',
AggInheritedGlobal = 'agg inherited global',
AggInheritedOverwritten = 'agg inherited overwritten',
}

View File

@@ -0,0 +1,6 @@
{
"extends": "../../../node_modules/@openstapps/configuration/tsconfig.json",
"compilerOptions": {
"skipLibCheck": true
}
}

View File

@@ -0,0 +1,34 @@
/*
* 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 {MappingDynamicTemplate, MappingProperty} from '@elastic/elasticsearch/lib/api/types';
export interface MapAggTestOptions {
testName: string;
name: string;
agg?: {
fields?: string[];
globals?: string[];
};
map?: MinimalMappingDescription;
err?: string[];
ignoredTags?: string[];
}
export interface MinimalMappingDescription {
maps?: {
[name: string]: MappingProperty;
};
dynamicTemplates?: Record<string, MappingDynamicTemplate>[];
}

View File

@@ -0,0 +1,142 @@
/*
* 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 {generateTemplate} from '../../src/mapping';
import path from 'path';
import {expect} from 'chai';
import {ProjectReflection} from 'typedoc';
import {getProjectReflection} from '../../src/project-reflection';
import {AggregationSchema, ESNestedAggregation} from '../../src/types/aggregation';
import {ElasticsearchTemplateCollection} from '../../src/types/mapping';
import {MapAggTestOptions, MinimalMappingDescription} from './map-agg-test-options';
import {settings} from '../../src/config/settings';
export class MapAggTest {
mapping_model_path!: string;
reflection!: ProjectReflection;
constructor(directory: string) {
// eslint-disable-next-line unicorn/prefer-module
this.mapping_model_path = path.resolve(__dirname, directory);
this.reflection = getProjectReflection(this.mapping_model_path);
}
testInterfaceAgainstPath(options: MapAggTestOptions) {
const template = generateTemplate(this.reflection, options.ignoredTags ?? [], false, [options.name]);
if (typeof options.err !== 'undefined') {
for (const error of template.errors) {
expect(options.err).to.include(error, 'Unexpected Error!');
}
} else {
expect(template.errors).to.be.deep.equal([], 'Unexpected Error!');
}
if (typeof options.agg !== 'undefined') {
const expectedAggSchema = MapAggTest.buildAggregation(
options.name,
options.agg.fields,
options.agg.globals,
);
expect(template.aggregations).to.be.deep.equal(expectedAggSchema, 'Aggregation schema not equal!');
}
if (typeof options.map !== 'undefined') {
const expectedMappingSchema = MapAggTest.buildMapping(options.name, options.map);
expect(template.mappings).to.be.deep.equal(expectedMappingSchema, 'Mapping schema not equal!');
}
}
static buildAggregation(name: string, fields?: string[], globals?: string[]): AggregationSchema {
const out: AggregationSchema = {
'@all': {
aggs: {},
filter: {
match_all: {},
},
},
};
for (const global of globals ?? []) {
(out['@all']! as ESNestedAggregation).aggs[global] = {
terms: {
field: `${global}.raw`,
size: 1000,
},
};
}
if (typeof fields === 'undefined' || fields.length === 0) {
return out;
}
out[name] = {
aggs: {},
filter: {
term: {
type: name,
},
},
};
for (const field of fields) {
(out[name]! as ESNestedAggregation).aggs[field] = {
terms: {
field: `${field}.raw`,
size: 1000,
},
};
}
return out;
}
static buildMapping(name: string, map: MinimalMappingDescription): ElasticsearchTemplateCollection {
let typeNameWithoutSpaces = name.toLowerCase();
while (typeNameWithoutSpaces.includes(' ')) {
typeNameWithoutSpaces = typeNameWithoutSpaces.replace(' ', '_');
}
const out: ElasticsearchTemplateCollection = {};
const templateName = `template_${typeNameWithoutSpaces}`;
out[templateName] = {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore empty object
mappings: {},
settings: settings,
index_patterns: [`stapps_${typeNameWithoutSpaces}*`],
};
const maps = map.maps ?? {};
maps.type = {
type: 'text',
};
maps.creation_date = {
type: 'date',
};
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore can be used to index
out[templateName].mappings = {
_source: {
excludes: ['creation_date'],
},
date_detection: false,
dynamic: 'strict',
properties: maps,
dynamic_templates: map.dynamicTemplates ?? [],
};
return out;
}
}

View File

@@ -0,0 +1,46 @@
/*
* 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 {ThingType} from './types';
import {MapAggTestOptions} from '../../map-agg-test-options';
/**
* @indexable
*/
export interface AnyUnknown {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
foo: any;
bar: unknown;
type: ThingType.AnyUnknown;
}
export const testConfig: MapAggTestOptions = {
testName: 'Any or unknown should create a dynamic field',
name: ThingType.AnyUnknown,
map: {
maps: {
foo: {
dynamic: true,
properties: {},
},
bar: {
dynamic: true,
properties: {},
},
},
},
};

View File

@@ -0,0 +1,50 @@
/*
* 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 {ThingType} from './types';
import {MapAggTestOptions} from '../../map-agg-test-options';
/**
* @date
*/
export type SCISO8601Date = string;
/**
* @indexable
*/
export interface DateAndRange {
/**
* @date
*/
directDate: string;
dateAlias: SCISO8601Date;
type: ThingType.Date;
}
export const testConfig: MapAggTestOptions = {
testName: 'Dates and date ranges should have the correct type',
name: ThingType.Date,
map: {
maps: {
directDate: {
type: 'date',
},
dateAlias: {
type: 'date',
},
},
},
};

View File

@@ -0,0 +1,48 @@
/*
* 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 {PARSE_ERROR} from '../../../../lib/config/typemap';
import {ThingType} from './types';
import {MapAggTestOptions} from '../../map-agg-test-options';
/**
* @indexable
*/
export interface DefaultGeneric {
foo: InterfaceWithDefaultGeneric;
type: ThingType.DefaultGeneric;
}
interface InterfaceWithDefaultGeneric<T = number> {
bar: T;
}
export const testConfig: MapAggTestOptions = {
testName: 'Default generics should fail',
name: ThingType.DefaultGeneric,
map: {
maps: {
foo: {
dynamic: 'strict',
properties: {
bar: {
type: PARSE_ERROR,
},
},
},
},
},
err: [`At "${ThingType.DefaultGeneric}::foo.bar" for Generic "T": Missing reflection, please report!`],
};

View File

@@ -0,0 +1,55 @@
/*
* 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 {TYPE_CONFLICT} from '../../../../lib/config/typemap';
import {ThingType} from './types';
import {MapAggTestOptions} from '../../map-agg-test-options';
/**
* @indexable
*/
export interface DoubleTypeConflict {
/**
* @keyword
* @text
*/
stringDoubleTypeConflict: string;
/**
* @integer
* @float
*/
numberDoubleTypeConflict: number;
type: ThingType.DoubleTypeConflict;
}
export const testConfig: MapAggTestOptions = {
testName: 'Double type annotations should cause an error',
name: ThingType.DoubleTypeConflict,
map: {
maps: {
stringDoubleTypeConflict: {
type: TYPE_CONFLICT,
},
numberDoubleTypeConflict: {
type: TYPE_CONFLICT,
},
},
},
err: [
`At "${ThingType.DoubleTypeConflict}::stringDoubleTypeConflict" for type "string": Type conflict; "keyword" would override "text"`,
`At "${ThingType.DoubleTypeConflict}::numberDoubleTypeConflict" for type "number": Type conflict; "integer" would override "float"`,
],
};

View File

@@ -0,0 +1,57 @@
/*
* 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 {ThingType} from './types';
import {MapAggTestOptions} from '../../map-agg-test-options';
/**
* @indexable
*/
export interface Enum {
foo: Bar;
bar: Baz;
type: ThingType.Enum;
}
enum Bar {
a,
b,
c,
}
enum Baz {
d = 'd',
// eslint-disable-next-line unicorn/prevent-abbreviations
e = 'e',
f = 'f',
}
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: {
foo: {
type: 'text',
},
bar: {
type: 'text',
},
},
},
};

View File

@@ -0,0 +1,88 @@
/*
* 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 {ThingType} from './types';
import {MapAggTestOptions} from '../../map-agg-test-options';
export type FilterableEnumType = 'a' | 'b' | 'c';
/**
* @indexable
*/
export interface FilterableTag {
/**
* @text
* @filterable
*/
foo: string;
/**
* @keyword
* @filterable
*/
bar: string;
/**
* @filterable
*/
baz: 'some literal';
/**
* @filterable
*/
buz: FilterableEnumType;
type: ThingType.FilterableTag;
}
export const testConfig: MapAggTestOptions = {
testName: 'Filterable tag should add raw field to strings',
name: ThingType.FilterableTag,
map: {
maps: {
foo: {
type: 'text',
fields: {
raw: {
type: 'keyword',
},
},
},
bar: {
type: 'keyword',
fields: {
raw: {
type: 'keyword',
},
},
},
baz: {
type: 'keyword',
fields: {
raw: {
type: 'keyword',
},
},
},
buz: {
type: 'keyword',
fields: {
raw: {
type: 'keyword',
},
},
},
},
},
};

View File

@@ -0,0 +1,59 @@
/*
* 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 {ThingType} from './types';
import {MapAggTestOptions} from '../../map-agg-test-options';
/**
* @indexable
*/
export interface Generics {
foo: InterfaceWithDefaultGeneric<number>;
baz: InterfaceWithStringGeneric<string>;
type: ThingType.Generics;
}
interface InterfaceWithDefaultGeneric<T = number> {
bar: T;
}
interface InterfaceWithStringGeneric<T> {
bar: T;
}
export const testConfig: MapAggTestOptions = {
testName: 'Generics should work',
name: ThingType.Generics,
map: {
maps: {
foo: {
dynamic: 'strict',
properties: {
bar: {
type: 'integer',
},
},
},
baz: {
dynamic: 'strict',
properties: {
bar: {
type: 'text',
},
},
},
},
},
};

View File

@@ -0,0 +1,40 @@
/*
* 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 {ThingType} from './types';
import {MapAggTestOptions} from '../../map-agg-test-options';
/**
* @indexable
*/
export interface ImpossibleUnion {
foo: 'a' | 1 | boolean;
type: ThingType.ImpossibleUnion;
}
export const testConfig: MapAggTestOptions = {
testName: 'Impossible union should cause an error',
name: ThingType.ImpossibleUnion,
map: {
maps: {
foo: {
type: 'boolean',
},
},
},
err: [
`At "${ThingType.ImpossibleUnion}::foo" for type "[{"type":"1","name":"2"},"unknown","1"]": Not implemented type`,
],
};

View File

@@ -0,0 +1,70 @@
/*
* 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 {ThingType} from './types';
import {MapAggTestOptions} from '../../map-agg-test-options';
/**
* @indexable
*/
export interface DoubleTypeConflict {
/**
* @keyword
*/
keywordNumber: number;
/**
* @text
*/
textNumber: number;
/**
* @integer
*/
integerString: string;
/**
* @float
*/
floatString: string;
type: ThingType.IncompatibleType;
}
export const testConfig: MapAggTestOptions = {
testName: 'Incompatible type annotations should cause an error and use defaults',
name: ThingType.IncompatibleType,
map: {
maps: {
keywordNumber: {
type: 'integer',
},
textNumber: {
type: 'integer',
},
integerString: {
type: 'text',
},
floatString: {
type: 'text',
},
},
},
err: [
`At "${ThingType.IncompatibleType}::keywordNumber" for tag "keyword": Not implemented tag`,
`At "${ThingType.IncompatibleType}::textNumber" for tag "text": Not implemented tag`,
`At "${ThingType.IncompatibleType}::floatString" for tag "float": Not implemented tag`,
`At "${ThingType.IncompatibleType}::integerString" for tag "integer": Not implemented tag`,
],
};

View File

@@ -0,0 +1,63 @@
/*
* 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 {ThingType} from './types';
import {MapAggTestOptions} from '../../map-agg-test-options';
/**
* @indexable
*/
export interface IndexSignature {
foo: {
[key: string]: {
bar: number;
baz: string;
};
};
type: ThingType.IndexSignature;
}
export const testConfig: MapAggTestOptions = {
testName: 'Index Signatures should work',
name: ThingType.IndexSignature,
map: {
maps: {
foo: {
dynamic: true,
properties: {},
},
},
dynamicTemplates: [
{
__type: {
mapping: {
dynamic: 'strict',
properties: {
bar: {
type: 'integer',
},
baz: {
type: 'text',
},
},
},
match: '*',
match_mapping_type: '*',
path_match: 'foo.*',
},
},
],
},
};

View File

@@ -0,0 +1,58 @@
/*
* 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 {MapAggTestOptions} from '../../map-agg-test-options';
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: 'date',
fields: {
raw: {
type: 'keyword',
},
},
},
bar: {
type: 'date',
},
},
},
};

View File

@@ -0,0 +1,55 @@
/*
* 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 {MapAggTestOptions} from '../../map-agg-test-options';
import {ThingType} from './types';
/**
* @indexable
*/
export interface InheritTags {
/**
* @inheritTags inherit tags::bar.baz
*/
foo: number;
bar: {
/**
* @float
*/
baz: number;
};
type: ThingType.InheritTags;
}
export const testConfig: MapAggTestOptions = {
testName: 'Inherit tags tag should work',
name: ThingType.InheritTags,
map: {
maps: {
foo: {
type: 'float',
},
bar: {
dynamic: 'strict',
properties: {
baz: {
type: 'float',
},
},
},
},
},
};

View File

@@ -0,0 +1,55 @@
/*
* 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 {ThingType} from './types';
import {MapAggTestOptions} from '../../map-agg-test-options';
/**
* @indexable
*/
export interface InheritedProperty extends Bar {
foo: number;
type: ThingType.InheritedProperty;
}
interface Bar {
/**
* @keyword
*/
bar: string;
/**
* @float
*/
baz: number;
}
export const testConfig: MapAggTestOptions = {
testName: 'Inherited properties should inherit tags',
name: ThingType.InheritedProperty,
map: {
maps: {
foo: {
type: 'integer',
},
bar: {
type: 'keyword',
},
baz: {
type: 'float',
},
},
},
};

View File

@@ -0,0 +1,42 @@
/* eslint-disable jsdoc/check-tag-names */
/*
* 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 {ThingType} from './types';
import {MapAggTestOptions} from '../../map-agg-test-options';
/**
* @indexable
*/
export interface InvalidTag {
/**
* @anInvalidTag
*/
foo: string;
type: ThingType.InvalidTag;
}
export const testConfig: MapAggTestOptions = {
testName: 'Invalid tags should cause an error',
name: ThingType.InvalidTag,
map: {
maps: {
foo: {
type: 'text',
},
},
},
err: [`At "${ThingType.InvalidTag}::foo" for tag "aninvalidtag": Not implemented tag`],
};

View File

@@ -0,0 +1,80 @@
/*
* 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 {ThingType} from './types';
import {MapAggTestOptions} from '../../map-agg-test-options';
/**
* @indexable
*/
export interface MapExplicitTypes {
/**
* @integer
*/
esInteger: number;
/**
* @float
*/
esFloat: number;
/**
* @keyword
*/
esKeyword: string;
/**
* @text
*/
esText: string;
/**
* @date
*/
esEpochMsDate: number;
/**
* @date
*/
esStringDate: string;
type: ThingType.MapExplicitTypes;
}
export const testConfig: MapAggTestOptions = {
testName: 'Explicit type annotations should work',
name: ThingType.MapExplicitTypes,
map: {
maps: {
esInteger: {
type: 'integer',
},
esFloat: {
type: 'float',
},
esKeyword: {
type: 'keyword',
},
esText: {
type: 'text',
},
esEpochMsDate: {
type: 'date',
},
esStringDate: {
type: 'date',
},
},
},
};

View File

@@ -0,0 +1,42 @@
/*
* 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 {MISSING_PREMAP} from '../../../../lib/config/typemap';
import {ThingType} from './types';
import {MapAggTestOptions} from '../../map-agg-test-options';
/**
* @indexable
*/
export interface MissingPremap {
// it really doesn't matter what we use here, as long as it is an external dependency
// if you get an error here because you removed a dependency, feel free to change it around
// to your heart's content
foo: HTMLAllCollection;
type: ThingType.MissingPremap;
}
export const testConfig: MapAggTestOptions = {
testName: 'Missing premap should cause an error',
name: ThingType.MissingPremap,
map: {
maps: {
foo: {
type: MISSING_PREMAP,
},
},
},
err: [`At "${ThingType.MissingPremap}::foo" for external type "HTMLAllCollection": Missing pre-map`],
};

View File

@@ -0,0 +1,69 @@
/*
* 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 {ThingType} from './types';
import {MapAggTestOptions} from '../../map-agg-test-options';
/**
* @indexable
*/
export interface Nested {
foo: {
depth1_1: {
depth2_1: {
depth3_1: number;
/**
* @keyword
*/
depth3_2: string;
};
depth2_2: boolean;
};
};
type: ThingType.Nested;
}
export const testConfig: MapAggTestOptions = {
testName: 'Nested properties should work',
name: ThingType.Nested,
map: {
maps: {
foo: {
dynamic: 'strict',
properties: {
depth1_1: {
dynamic: 'strict',
properties: {
depth2_1: {
dynamic: 'strict',
properties: {
depth3_1: {
type: 'integer',
},
depth3_2: {
type: 'keyword',
},
},
},
depth2_2: {
type: 'boolean',
},
},
},
},
},
},
},
};

View File

@@ -0,0 +1,62 @@
/*
* 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 {ThingType} from './types';
import {MapAggTestOptions} from '../../map-agg-test-options';
/**
* @indexable
*/
export interface ObjectUnion {
foo: Boo | Buu;
type: ThingType.ObjectUnion;
}
// we can't name them Bar or Baz, look here for more info:
// https://gitlab.com/openstapps/core-tools/-/issues/48
// or here
// https://github.com/TypeStrong/typedoc/issues/1373
interface Boo {
a: boolean;
intersection: string;
}
interface Buu {
b: number;
intersection: string;
}
export const testConfig: MapAggTestOptions = {
testName: 'Object union types should work',
name: ThingType.ObjectUnion,
map: {
maps: {
foo: {
dynamic: 'strict',
properties: {
a: {
type: 'boolean',
},
b: {
type: 'integer',
},
intersection: {
type: 'text',
},
},
},
},
},
};

View File

@@ -0,0 +1,68 @@
/*
* 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 {ThingType} from './types';
import {MapAggTestOptions} from '../../map-agg-test-options';
/**
* @indexable
*/
export interface PairedTags {
/**
* @keyword
* @filterable
*/
foo: string;
/**
* @text
* @filterable
* @sortable
*/
bar: string;
type: ThingType.PairedTags;
}
export const testConfig: MapAggTestOptions = {
testName: 'Tags should be able to be paired',
name: ThingType.PairedTags,
map: {
maps: {
foo: {
type: 'keyword',
fields: {
raw: {
type: 'keyword',
},
},
},
bar: {
type: 'text',
fields: {
raw: {
type: 'keyword',
},
sort: {
country: 'DE',
language: 'de',
type: 'icu_collation_keyword',
variant: '@collation=phonebook',
// eslint-disable-next-line @typescript-eslint/no-explicit-any
} as any,
},
},
},
},
};

View File

@@ -0,0 +1,57 @@
/*
* 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 {ThingType} from './types';
import {MapAggTestOptions} from '../../map-agg-test-options';
/**
* @indexable
*/
export interface SensibleDefaults {
numberDefault: number;
stringDefault: string;
booleanDefault: boolean;
stringLiteralDefault: 'Hey there!';
booleanTrueLiteralDefault: true;
booleanFalseLiteralDefault: false;
type: ThingType.SensibleDefaultType;
}
export const testConfig: MapAggTestOptions = {
testName: 'Primitive types should have sensible defaults',
name: ThingType.SensibleDefaultType,
map: {
maps: {
numberDefault: {
type: 'integer',
},
stringDefault: {
type: 'text',
},
booleanDefault: {
type: 'boolean',
},
stringLiteralDefault: {
type: 'keyword',
},
booleanTrueLiteralDefault: {
type: 'boolean',
},
booleanFalseLiteralDefault: {
type: 'boolean',
},
},
},
};

View File

@@ -0,0 +1,83 @@
/*
* 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 {ThingType} from './types';
import {MapAggTestOptions} from '../../map-agg-test-options';
/**
* @indexable
*/
export interface SortableTag {
/**
* @sortable
*/
foo: string;
/**
* @sortable ducet
*/
bar: string;
/**
* @sortable
*/
baz: number;
type: ThingType.SortableTag;
}
export const testConfig: MapAggTestOptions = {
testName: 'Sortable tag should work',
name: ThingType.SortableTag,
map: {
maps: {
foo: {
type: 'text',
fields: {
sort: {
country: 'DE',
language: 'de',
type: 'icu_collation_keyword',
variant: '@collation=phonebook',
// eslint-disable-next-line @typescript-eslint/no-explicit-any
} as any,
},
},
bar: {
type: 'text',
fields: {
sort: {
country: 'DE',
language: 'de',
type: 'icu_collation_keyword',
variant: '@collation=phonebook',
// eslint-disable-next-line @typescript-eslint/no-explicit-any
} as any,
},
},
baz: {
type: 'integer',
fields: {
sort: {
country: 'DE',
language: 'de',
type: 'icu_collation_keyword',
variant: '@collation=phonebook',
// eslint-disable-next-line @typescript-eslint/no-explicit-any
} as any,
},
},
},
},
};

View File

@@ -0,0 +1,63 @@
/*
* 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 {ThingType} from './types';
import {MapAggTestOptions} from '../../map-agg-test-options';
/**
* @indexable
*/
export interface TagsIgnoreCase {
/**
* @inheritTags inherit tags::bar.baz
*/
camelCase: number;
/**
* @inheritTags inherit tags::bar.baz
*/
lowerCase: number;
bar: {
/**
* @float
*/
baz: number;
};
type: ThingType.TagsIgnoreCase;
}
export const testConfig: MapAggTestOptions = {
testName: 'Tags should ignore case',
name: ThingType.TagsIgnoreCase,
map: {
maps: {
camelCase: {
type: 'float',
},
lowerCase: {
type: 'float',
},
bar: {
dynamic: 'strict',
properties: {
baz: {
type: 'float',
},
},
},
},
},
};

View File

@@ -0,0 +1,66 @@
/*
* 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 {ThingType} from './types';
import {MapAggTestOptions} from '../../map-agg-test-options';
/**
* @indexable
*/
export interface TypeAlias {
/**
*
*/
textProperty: ATextAlias;
/**
*
*/
keywordProperty: AKeywordAlias;
/**
* @keyword
*/
overriddenTextAsKeyword: ATextAlias;
type: ThingType.TypeAlias;
}
/**
* @text
*/
type ATextAlias = string;
/**
* @keyword
*/
type AKeywordAlias = string;
export const testConfig: MapAggTestOptions = {
testName: 'Type alias annotations should work',
name: ThingType.TypeAlias,
map: {
maps: {
textProperty: {
type: 'text',
},
keywordProperty: {
type: 'keyword',
},
overriddenTextAsKeyword: {
type: 'keyword',
},
},
},
};

View File

@@ -0,0 +1,41 @@
/*
* Copyright (C) 2021 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 {ThingType} from './types';
import {MapAggTestOptions} from '../../map-agg-test-options';
export interface SCISO8601DateRange {
bar: string;
}
/**
* @indexable
*/
export interface TypeOverrides {
foo: SCISO8601DateRange;
type: ThingType.TypeOverrides;
}
export const testConfig: MapAggTestOptions = {
testName: 'Premaps should support non-external types',
name: ThingType.TypeOverrides,
map: {
maps: {
foo: {
type: 'date_range',
},
},
},
};

View File

@@ -0,0 +1,44 @@
/*
* 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 {ThingType} from './types';
import {MapAggTestOptions} from '../../map-agg-test-options';
/**
* @indexable
*/
export interface TypeQuery {
foo: typeof Bar;
type: ThingType.TypeQuery;
}
enum Bar {
'a',
'b',
'c',
}
// https://gitlab.com/openstapps/core-tools/-/issues/47
export const testConfig: MapAggTestOptions = {
testName: 'Type queries should work',
name: ThingType.TypeQuery,
map: {
maps: {
foo: {
type: 'text',
},
},
},
};

View File

@@ -0,0 +1,66 @@
/*
* 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 {ThingType} from './types';
import {MapAggTestOptions} from '../../map-agg-test-options';
/**
* @indexable
*/
export interface TypeWrapperInheritance {
/**
* @float
*/
numberWrapper: NumberWrapper;
/**
* @keyword
*/
stringWrapper: StringWrapper;
/**
* @text
*/
stringLiteralWrapper: StringLiteralWrapper;
type: ThingType.TypeWrapperInheritance;
}
type NumberWrapper = number;
type StringWrapper = string;
type StringLiteralWrapper = 'foo';
// https://gitlab.com/openstapps/core-tools/-/merge_requests/29
export const testConfig: MapAggTestOptions = {
testName: 'Wrapper types should inherit tags',
name: ThingType.TypeWrapperInheritance,
map: {
maps: {
foo: {
dynamic: 'strict',
properties: {
numberWrapper: {
type: 'float',
},
stringWrapper: {
type: 'keyword',
},
stringLiteralWrapper: {
type: 'text',
},
},
},
},
},
};

View File

@@ -0,0 +1,43 @@
/*
* Copyright (C) 2020-2021 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/>.
*/
export enum ThingType {
MapExplicitTypes = 'map explicit types',
DoubleTypeConflict = 'double type conflict',
IncompatibleType = 'incompatible type',
SensibleDefaultType = 'sensible default',
InvalidTag = 'invalid tag',
MissingPremap = 'missing premap',
DefaultGeneric = 'default generic',
Generics = 'generics',
Nested = 'nested',
IndexSignature = 'index signature',
ImpossibleUnion = 'impossible union',
TypeQuery = 'type query',
ObjectUnion = 'object union',
TypeWrapperInheritance = 'type wrapper inheritance',
SortableTag = 'sortable tag',
Enum = 'enum',
InheritedProperty = 'inherited property',
PairedTags = 'paired tags',
FilterableTag = 'filterable tag',
AnyUnknown = 'any unknown',
InferredTypeFilterable = 'inferred type filterable',
Date = 'date',
InheritTags = 'inherit tags',
TagsIgnoreCase = 'tags ignore case',
TypeAlias = 'type alias',
TypeOverrides = 'type overrides',
}

View File

@@ -0,0 +1,6 @@
{
"extends": "../../../node_modules/@openstapps/configuration/tsconfig.json",
"compilerOptions": {
"skipLibCheck": true
}
}

View File

@@ -0,0 +1,59 @@
/*
* Copyright (C) 2020-2021 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 {Logger} from '@openstapps/logger';
import {readdirSync, statSync} from 'fs';
import path from 'path';
import {MapAggTest} from './mapping-model/map-agg-test';
import {MapAggTestOptions} from './mapping-model/map-agg-test-options';
describe('ES Mapping Gen', async () => {
const magAppInstance = new MapAggTest('mappings');
/**
* Expand a path to a list of all files deeply contained in it
*/
// eslint-disable-next-line unicorn/consistent-function-scoping
function expandPathToFilesSync(sourcePath: string, accept: (fileName: string) => boolean): string[] {
const fullPath = path.resolve(sourcePath);
const directory = statSync(fullPath);
return directory.isDirectory()
? // eslint-disable-next-line unicorn/prefer-spread
([] as string[]).concat(
...readdirSync(fullPath).map(fragment =>
expandPathToFilesSync(path.resolve(sourcePath, fragment), accept),
),
)
: [fullPath].filter(accept);
}
for (const file of expandPathToFilesSync('./test/mapping-model/mappings/', file =>
file.endsWith('mapping-test.ts'),
)) {
try {
// eslint-disable-next-line unicorn/no-await-expression-member
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);
}
}
})
.timeout(20_000)
.slow(10_000);