Resolve "Retype mapping generation using @elastic/elasticsearch"

This commit is contained in:
Thea Schöbl
2023-04-28 11:15:08 +00:00
committed by Rainer Killinger
parent fc850fe7ac
commit d90416e201
42 changed files with 441 additions and 596 deletions

132
package-lock.json generated
View File

@@ -91,6 +91,57 @@
"@jridgewell/trace-mapping": "0.3.9"
}
},
"@elastic/elasticsearch": {
"version": "8.4.0",
"resolved": "https://registry.npmjs.org/@elastic/elasticsearch/-/elasticsearch-8.4.0.tgz",
"integrity": "sha512-0QZDBePnb5a+d76zjlMYq96IDf0AOuGP7JHugFUYlYwTC7rZvROuZSpoUsvpUjNH2CzMqWgNLIekIR6EHRMIQA==",
"requires": {
"@elastic/transport": "^8.2.0",
"tslib": "^2.4.0"
},
"dependencies": {
"tslib": {
"version": "2.5.0",
"resolved": "https://registry.npmjs.org/tslib/-/tslib-2.5.0.tgz",
"integrity": "sha512-336iVw3rtn2BUK7ORdIAHTyxHGRIHVReokCR3XjbckJMK7ms8FysBfhLR8IXnAgy7T0PTPNBWKiH514FOW/WSg=="
}
}
},
"@elastic/transport": {
"version": "8.3.1",
"resolved": "https://registry.npmjs.org/@elastic/transport/-/transport-8.3.1.tgz",
"integrity": "sha512-jv/Yp2VLvv5tSMEOF8iGrtL2YsYHbpf4s+nDsItxUTLFTzuJGpnsB/xBlfsoT2kAYEnWHiSJuqrbRcpXEI/SEQ==",
"requires": {
"debug": "^4.3.4",
"hpagent": "^1.0.0",
"ms": "^2.1.3",
"secure-json-parse": "^2.4.0",
"tslib": "^2.4.0",
"undici": "^5.5.1"
},
"dependencies": {
"debug": {
"version": "4.3.4",
"resolved": "https://registry.npmjs.org/debug/-/debug-4.3.4.tgz",
"integrity": "sha512-PRWFHuSU3eDtQJPvnNY7Jcket1j0t5OuOsFzPPzsekD52Zl8qUfFIPEiswXqIvHWGVHOgX+7G/vCNNhehwxfkQ==",
"requires": {
"ms": "2.1.2"
},
"dependencies": {
"ms": {
"version": "2.1.2",
"resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz",
"integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w=="
}
}
},
"tslib": {
"version": "2.5.0",
"resolved": "https://registry.npmjs.org/tslib/-/tslib-2.5.0.tgz",
"integrity": "sha512-336iVw3rtn2BUK7ORdIAHTyxHGRIHVReokCR3XjbckJMK7ms8FysBfhLR8IXnAgy7T0PTPNBWKiH514FOW/WSg=="
}
}
},
"@es-joy/jsdoccomment": {
"version": "0.31.0",
"resolved": "https://registry.npmjs.org/@es-joy/jsdoccomment/-/jsdoccomment-0.31.0.tgz",
@@ -196,6 +247,32 @@
"fastq": "^1.6.0"
}
},
"@openstapps/configuration": {
"version": "0.34.0",
"resolved": "https://registry.npmjs.org/@openstapps/configuration/-/configuration-0.34.0.tgz",
"integrity": "sha512-woPn4v3mQMUibtRs84VDpiC0EarowA4HvtpXbzc6ddWcYs8jtPLwA+mSbWSiROhJ2CeRQTJtMK+bJ4yhIRfdKw==",
"dev": true,
"requires": {
"@types/node": "14.18.36",
"@types/semver": "7.3.13",
"@types/yaml": "1.9.7",
"chalk": "4.1.2",
"commander": "9.5.0",
"semver": "7.3.8",
"yaml": "1.10.2"
},
"dependencies": {
"semver": {
"version": "7.3.8",
"resolved": "https://registry.npmjs.org/semver/-/semver-7.3.8.tgz",
"integrity": "sha512-NB1ctGL5rlHrPJtFDVIVzTyQylMLu9N9VICA6HSFJo8MCGVTMW6gfpicwKmmK/dAjTOrqu5l63JJOpDSrAis3A==",
"dev": true,
"requires": {
"lru-cache": "^6.0.0"
}
}
}
},
"@openstapps/eslint-config": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/@openstapps/eslint-config/-/eslint-config-1.1.0.tgz",
@@ -404,6 +481,21 @@
"@types/node": "*"
}
},
"@types/semver": {
"version": "7.3.13",
"resolved": "https://registry.npmjs.org/@types/semver/-/semver-7.3.13.tgz",
"integrity": "sha512-21cFJr9z3g5dW8B0CVI9g2O9beqaThGQ6ZFBqHfwhzLDKUxaqTIy3vnfah/UPkfOiF2pLq+tGz+W8RyCskuslw==",
"dev": true
},
"@types/yaml": {
"version": "1.9.7",
"resolved": "https://registry.npmjs.org/@types/yaml/-/yaml-1.9.7.tgz",
"integrity": "sha512-8WMXRDD1D+wCohjfslHDgICd2JtMATZU8CkhH8LVJqcJs6dyYj5TGptzP8wApbmEullGBSsCEzzap73DQ1HJaA==",
"dev": true,
"requires": {
"yaml": "*"
}
},
"@typescript-eslint/eslint-plugin": {
"version": "5.40.0",
"resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-5.40.0.tgz",
@@ -782,6 +874,14 @@
"integrity": "sha512-qhAVI1+Av2X7qelOfAIYwXONood6XlZE/fXaBSmW/T5SzLAmCgzi+eiWE7fUvbHaeNBQH13UftjpXxsfLkMpgw==",
"dev": true
},
"busboy": {
"version": "1.6.0",
"resolved": "https://registry.npmjs.org/busboy/-/busboy-1.6.0.tgz",
"integrity": "sha512-8SFQbg/0hQ9xy3UNTB0YEnsNBbWfhf7RtnzpL7TkBiTBRfrQ9Fxcnz7VJsleJpyp6rVLvXiuORqjlHi5q+PYuA==",
"requires": {
"streamsearch": "^1.1.0"
}
},
"cacheable-lookup": {
"version": "5.0.4",
"resolved": "https://registry.npmjs.org/cacheable-lookup/-/cacheable-lookup-5.0.4.tgz",
@@ -2071,6 +2171,11 @@
"lru-cache": "^6.0.0"
}
},
"hpagent": {
"version": "1.2.0",
"resolved": "https://registry.npmjs.org/hpagent/-/hpagent-1.2.0.tgz",
"integrity": "sha512-A91dYTeIB6NoXG+PxTQpCCDDnfHsW9kc06Lvpu1TEe9gnd6ZFeiBoRO9JvzEv6xK7EX97/dUE8g/vBMTqTS3CA=="
},
"http-cache-semantics": {
"version": "4.1.0",
"resolved": "https://registry.npmjs.org/http-cache-semantics/-/http-cache-semantics-4.1.0.tgz",
@@ -2737,8 +2842,7 @@
"ms": {
"version": "2.1.3",
"resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz",
"integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==",
"dev": true
"integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA=="
},
"nanoid": {
"version": "3.3.1",
@@ -3269,6 +3373,11 @@
"regexp-tree": "~0.1.1"
}
},
"secure-json-parse": {
"version": "2.7.0",
"resolved": "https://registry.npmjs.org/secure-json-parse/-/secure-json-parse-2.7.0.tgz",
"integrity": "sha512-6aU+Rwsezw7VR8/nyvKTx8QpWH9FrcYiXXlqC4z5d5XQBDRqtbfsRjnwGyqbi3gddNtWHuEk9OANUotL26qKUw=="
},
"semver": {
"version": "6.3.0",
"resolved": "https://registry.npmjs.org/semver/-/semver-6.3.0.tgz",
@@ -3370,6 +3479,11 @@
"readable-stream": "^3.0.0"
}
},
"streamsearch": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/streamsearch/-/streamsearch-1.1.0.tgz",
"integrity": "sha512-Mcc5wHehp9aXz1ax6bZUyY5afg9u2rv5cqQI3mRrYkGC8rW2hM02jWuwjtL++LS5qinSyhj2QfLyNsuc+VsExg=="
},
"string-width": {
"version": "4.2.3",
"resolved": "https://registry.npmjs.org/string-width/-/string-width-4.2.3.tgz",
@@ -3592,6 +3706,14 @@
"integrity": "sha512-T9q82TJI9e/C1TAxYvfb16xO120tMVFZrGA3f9/P4424DNu6ypK103y0GPFVa17yotwSyZW5iYXgjYHkGrJW/g==",
"optional": true
},
"undici": {
"version": "5.22.0",
"resolved": "https://registry.npmjs.org/undici/-/undici-5.22.0.tgz",
"integrity": "sha512-fR9RXCc+6Dxav4P9VV/sp5w3eFiSdOjJYsbtWfd4s5L5C4ogyuVpdKIVHeW0vV1MloM65/f7W45nR9ZxwVdyiA==",
"requires": {
"busboy": "^1.6.0"
}
},
"universalify": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/universalify/-/universalify-2.0.0.tgz",
@@ -3694,6 +3816,12 @@
"integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==",
"dev": true
},
"yaml": {
"version": "1.10.2",
"resolved": "https://registry.npmjs.org/yaml/-/yaml-1.10.2.tgz",
"integrity": "sha512-r3vXyErRCYJ7wg28yvBY5VSoAF8ZvlcW9/BwUzEtUsjvX/DKs24dIkuwjtuprwJJHsbyUbLApepYTR1BN4uHrg==",
"dev": true
},
"yargs": {
"version": "16.2.0",
"resolved": "https://registry.npmjs.org/yargs/-/yargs-16.2.0.tgz",

View File

@@ -24,6 +24,7 @@
"lint:fix": "eslint --fix -c .eslintrc --ignore-path .eslintignore --ext .ts src/ test/"
},
"dependencies": {
"@elastic/elasticsearch": "8.4.0",
"@openstapps/logger": "1.1.1",
"commander": "9.5.0",
"deepmerge": "4.2.2",
@@ -33,6 +34,7 @@
"typescript": "3.8.3"
},
"devDependencies": {
"@openstapps/configuration": "0.34.0",
"@testdeck/mocha": "0.3.3",
"@openstapps/eslint-config": "1.1.0",
"@types/chai": "4.3.4",

View File

@@ -12,8 +12,8 @@
* 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 {ElasticsearchFieldmap, ElasticsearchFilterableMap} from '../types/mapping';
import {ElasticsearchDataType} from './typemap';
import {MappingProperty} from '@elastic/elasticsearch/lib/api/types';
import {ElasticsearchFieldmap, SimpleType} from '../types/mapping';
const ducetSort = {
type: 'icu_collation_keyword',
@@ -22,12 +22,14 @@ const ducetSort = {
variant: '@collation=phonebook',
};
const keyword: MappingProperty['type'] = 'keyword';
export const fieldmap: ElasticsearchFieldmap = {
aggregatable: {
default: {
raw: {
ignore_above: 10_000,
type: ElasticsearchDataType.keyword,
type: keyword,
},
},
ignore: ['global'],
@@ -45,9 +47,9 @@ export const fieldmap: ElasticsearchFieldmap = {
export const filterableTagName = 'filterable';
export const filterableMap: ElasticsearchFilterableMap = {
date: ElasticsearchDataType.keyword,
keyword: ElasticsearchDataType.keyword,
text: ElasticsearchDataType.keyword,
integer: ElasticsearchDataType.integer,
export const filterableMap: Record<string, SimpleType> = {
date: 'keyword',
keyword: 'keyword',
text: 'keyword',
integer: 'integer',
};

View File

@@ -12,53 +12,52 @@
* 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 {ElasticsearchPremap} from '../types/mapping';
import {ElasticsearchDataType} from './typemap';
import {MappingProperty} from '@elastic/elasticsearch/lib/api/types';
export const premaps: ElasticsearchPremap = {
export const premaps: Record<string, MappingProperty> = {
'CoordinateReferenceSystem': {
dynamic: true,
properties: {
type: {
type: ElasticsearchDataType.keyword,
type: 'keyword',
},
},
},
'LineString': {
type: ElasticsearchDataType.geo_shape,
type: 'geo_shape',
},
'Point': {
properties: {
type: {
type: ElasticsearchDataType.keyword,
type: 'keyword',
},
coordinates: {
type: ElasticsearchDataType.geo_point,
type: 'geo_point',
},
},
dynamic: 'strict',
},
'Polygon': {
type: ElasticsearchDataType.geo_shape,
type: 'geo_shape',
},
'SCISO8601DateRange': {
type: ElasticsearchDataType.date_range,
type: 'date_range',
},
'jsonpatch.OpPatch': {
dynamic: 'strict',
properties: {
from: {
type: ElasticsearchDataType.keyword,
type: 'keyword',
},
op: {
type: ElasticsearchDataType.keyword,
type: 'keyword',
},
path: {
type: ElasticsearchDataType.keyword,
type: 'keyword',
},
value: {
// this is actually an 'any' type, however ES does not really support that.
type: ElasticsearchDataType.keyword,
// this is actually an 'any' type; however, ES does not really support that.
type: 'keyword',
},
},
},

View File

@@ -12,9 +12,9 @@
* 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 {ElasticsearchSettings} from '../types/mapping';
import {IndicesPutTemplateRequest} from '@elastic/elasticsearch/lib/api/types';
export const settings: ElasticsearchSettings = {
export const settings: IndicesPutTemplateRequest['settings'] = {
'mapping.total_fields.limit': 10_000,
'max_result_window': 30_000,
'number_of_replicas': 0,

View File

@@ -12,58 +12,37 @@
* 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 {MappingFloatNumberProperty} from '@elastic/elasticsearch/lib/api/types';
import {ElasticsearchTypemap} from '../types/mapping';
export enum ElasticsearchDataType {
missing_premap = 'MISSING_PREMAP',
parse_error = 'PARSE_ERROR',
type_conflict = 'TYPE_CONFLICT',
text = 'text',
keyword = 'keyword',
date = 'date',
// long = 'long',
// double = 'double',
float = 'float',
boolean = 'boolean',
ip = 'ip',
integer = 'integer',
object = 'object',
nested = 'nested',
geo_point = 'geo_point',
geo_shape = 'geo_shape',
completion = 'completion',
date_range = 'date_range',
// integer_range = 'integer_range',
// float_range = 'float_range',
// long_range = 'long_range',
// double_range = 'double_range',
// ip_range = 'ip_range',
}
export const PARSE_ERROR = 'PARSE_ERROR' as MappingFloatNumberProperty['type'];
export const MISSING_PREMAP = 'MISSING_PREMAP' as MappingFloatNumberProperty['type'];
export const TYPE_CONFLICT = 'TYPE_CONFLICT' as MappingFloatNumberProperty['type'];
export const typemap: ElasticsearchTypemap = {
boolean: {
default: ElasticsearchDataType.boolean,
default: 'boolean',
},
false: {
default: ElasticsearchDataType.boolean,
default: 'boolean',
},
number: {
default: ElasticsearchDataType.integer,
float: ElasticsearchDataType.float,
integer: ElasticsearchDataType.integer,
date: ElasticsearchDataType.date,
default: 'integer',
float: 'float',
integer: 'integer',
date: 'date',
},
string: {
default: ElasticsearchDataType.text,
keyword: ElasticsearchDataType.keyword,
text: ElasticsearchDataType.text,
date: ElasticsearchDataType.date,
default: 'text',
keyword: 'keyword',
text: 'text',
date: 'date',
},
stringLiteral: {
default: ElasticsearchDataType.keyword,
default: 'keyword',
},
true: {
default: ElasticsearchDataType.boolean,
default: 'boolean',
},
};

View File

@@ -12,6 +12,11 @@
* 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,
MappingObjectProperty,
MappingProperty,
} from '@elastic/elasticsearch/lib/api/types';
import {Logger} from '@openstapps/logger';
import merge from 'deepmerge';
import {stringify} from 'flatted';
@@ -31,18 +36,11 @@ import {
import {fieldmap, filterableMap, filterableTagName} from './config/fieldmap';
import {premaps} from './config/premap';
import {settings} from './config/settings';
import {dynamicTypes, ElasticsearchDataType, isTagType, typemap} from './config/typemap';
import {dynamicTypes, isTagType, MISSING_PREMAP, PARSE_ERROR, TYPE_CONFLICT, typemap} from './config/typemap';
import {AggregationSchema, ESNestedAggregation} from './types/aggregation';
import {
ElasticsearchDynamicTemplate,
ElasticsearchObject,
ElasticsearchTemplateCollection,
ElasticsearchType,
ElasticsearchValue,
MappingGenTemplate,
} from './types/mapping';
import {ElasticsearchTemplateCollection, MappingGenTemplate} from './types/mapping';
let dynamicTemplates: ElasticsearchDynamicTemplate[] = [];
let dynamicTemplates: Record<string, MappingDynamicTemplate>[] = [];
let errors: string[] = [];
let showErrors = true;
@@ -148,11 +146,11 @@ function trimString(value: string, maxLength: number): string {
*/
function getReflectionGeneric(
type: ReferenceType,
out: Map<string, ElasticsearchValue>,
out: Map<string, MappingProperty>,
topTypeName: string,
path: string,
tags: CommentTag[],
): Map<string, ElasticsearchValue> {
): Map<string, MappingProperty> {
if (
typeof type.typeArguments !== 'undefined' &&
type.reflection instanceof DeclarationReflection &&
@@ -196,11 +194,11 @@ function getReflectionGeneric(
*/
function handleExternalType(
ref: ReferenceType,
generics: Map<string, ElasticsearchValue>,
generics: Map<string, MappingProperty>,
path: string,
topTypeName: string,
tags: CommentTag[],
): ElasticsearchValue {
): MappingProperty {
for (const premap of Object.keys(premaps)) {
if (premap === ref.name) {
return readFieldTags(premaps[premap], path, topTypeName, tags);
@@ -212,7 +210,7 @@ function handleExternalType(
if (typeof ref.typeArguments === 'undefined' || typeof ref.typeArguments[0] === 'undefined') {
composeErrorMessage(path, topTypeName, 'Array with generics', 'array', 'Failed to parse');
return {type: ElasticsearchDataType.parse_error};
return {type: PARSE_ERROR};
}
return readFieldTags(
@@ -238,7 +236,7 @@ function handleExternalType(
composeErrorMessage(path, topTypeName, 'external type', ref.name, 'Missing pre-map');
return readFieldTags({type: ElasticsearchDataType.missing_premap}, path, topTypeName, tags);
return readFieldTags({type: MISSING_PREMAP}, path, topTypeName, tags);
}
/**
@@ -252,25 +250,20 @@ function handleExternalType(
*/
function handleDeclarationReflection(
decl: DeclarationReflection,
generics: Map<string, ElasticsearchValue>,
generics: Map<string, MappingProperty>,
path: string,
topTypeName: string,
inheritedTags?: CommentTag[],
): ElasticsearchValue {
): MappingProperty {
// check if we have an object referencing a generic
if (generics.has(decl.name)) {
// if the object name is the same as the generic name
return readFieldTags(
generics.get(decl.name) as ElasticsearchObject | ElasticsearchType,
path,
topTypeName,
decl.comment?.tags ?? [],
);
return readFieldTags(generics.get(decl.name)!, path, topTypeName, decl.comment?.tags ?? []);
// use the value defined by the generic
}
// start the actual handling process
const out: ElasticsearchObject = {
const out: MappingProperty = {
dynamic: 'strict',
properties: {},
};
@@ -282,7 +275,7 @@ function handleDeclarationReflection(
if (typeof decl.indexSignature.type !== 'undefined') {
empty = false;
const template: ElasticsearchDynamicTemplate = {};
const template: Record<string, MappingDynamicTemplate> = {};
template[decl.name] = {
mapping: handleType(
decl.indexSignature.type,
@@ -307,7 +300,7 @@ function handleDeclarationReflection(
if (typeof decl.children !== 'undefined' && decl.children.length > 0) {
for (const child of decl.children) {
empty = false;
out.properties[child.name] = handleDeclarationReflection(
out.properties![child.name] = handleDeclarationReflection(
child,
new Map(generics),
`${path}${child.name}.`,
@@ -461,12 +454,12 @@ function arrayPriorityJoin(originals: CommentTag[], overrider: CommentTag[]): Co
*/
function handleUnionType(
type: UnionType,
generics: Map<string, ElasticsearchValue>,
generics: Map<string, MappingProperty>,
path: string,
topTypeName: string,
tags: CommentTag[],
): ElasticsearchValue {
const list: ElasticsearchValue[] = [];
): MappingProperty {
const list: MappingProperty[] = [];
for (const subType of type.types) {
if (subType instanceof IntrinsicType && subType.name === 'undefined') {
@@ -479,7 +472,7 @@ function handleUnionType(
let out = list[0];
for (const item of list) {
out = merge<ElasticsearchValue>(out, item);
out = merge<MappingProperty>(out, item);
}
return out;
@@ -493,7 +486,7 @@ function handleUnionType(
'Empty union type. This is likely not a user error.',
);
return {type: ElasticsearchDataType.parse_error};
return {type: PARSE_ERROR};
}
/**
@@ -507,11 +500,11 @@ function handleUnionType(
*/
function handleType(
type: Type,
generics: Map<string, ElasticsearchValue>,
generics: Map<string, MappingProperty>,
path: string,
topTypeName: string,
tags: CommentTag[],
): ElasticsearchValue {
): MappingProperty {
// logger.log((type as any).name);
if (type instanceof ArrayType) {
// array is irrelevant in Elasticsearch, so just go with the element type
@@ -556,11 +549,11 @@ function handleType(
if (type instanceof TypeParameterType) {
// check if we have an object referencing a generic
if (generics.has(type.name)) {
return generics.get(type.name) as ElasticsearchObject | ElasticsearchType;
return generics.get(type.name)!;
}
composeErrorMessage(path, topTypeName, 'Generic', type.name, 'Missing reflection, please report!');
return {type: ElasticsearchDataType.parse_error};
return {type: PARSE_ERROR};
}
if (type instanceof ReflectionType) {
return readFieldTags(
@@ -573,7 +566,7 @@ function handleType(
composeErrorMessage(path, topTypeName, 'type', stringify(type), 'Not implemented type');
return {type: ElasticsearchDataType.parse_error};
return {type: PARSE_ERROR};
}
/**
@@ -617,12 +610,12 @@ function addAggregatable(path: string, topTypeName: string, global: boolean) {
* @param dataType the ElasticsearchDataType, for checking if a tag is a type tag
*/
function readFieldTags(
previous: ElasticsearchValue,
previous: MappingProperty,
path: string,
topTypeName: string,
tags: CommentTag[],
dataType?: string,
): ElasticsearchValue {
): MappingProperty {
for (const tag of tags) {
if (tag.tagName === aggregatableTag) {
addAggregatable(path, topTypeName, tag.text.trim() === aggregatableTagParameterGlobal);
@@ -655,7 +648,7 @@ function readFieldTags(
previous.fields = {};
}
if ('type' in previous) {
const type = filterableMap[previous.type];
const type = filterableMap[previous.type!];
if (typeof type !== 'undefined') {
// merge fields
previous.fields = {...previous.fields, raw: {type: type}};
@@ -688,13 +681,8 @@ function readFieldTags(
* @param topTypeName the name of the SCThingType
* @param tags tags attached to the value
*/
function readTypeTags(
type: string,
path: string,
topTypeName: string,
tags: CommentTag[],
): ElasticsearchValue {
let out: ElasticsearchValue = {type: ElasticsearchDataType.parse_error};
function readTypeTags(type: string, path: string, topTypeName: string, tags: CommentTag[]): MappingProperty {
let out: MappingProperty = {type: PARSE_ERROR};
if (typeof typemap[type] !== 'undefined') {
// first look if the value has a definition in the typemap
@@ -704,23 +692,25 @@ function readTypeTags(
typeof typemap[type][tags[i].tagName] !== 'undefined'
) {
// if we have a tag that indicates a type
if (out.type !== ElasticsearchDataType.parse_error) {
if (out.type !== PARSE_ERROR) {
composeErrorMessage(
path,
topTypeName,
'type',
type,
`Type conflict; "${typemap[type][tags[i].tagName]}" would override "${out.type}"`,
`Type conflict; "${typemap[type][tags[i].tagName]}" would override "${
(out as MappingProperty).type
}"`,
);
out.type = ElasticsearchDataType.type_conflict;
(out as MappingProperty).type = TYPE_CONFLICT;
continue;
}
out.type = typemap[type][tags[i].tagName];
(out as MappingProperty).type = typemap[type][tags[i].tagName];
}
}
if (out.type === ElasticsearchDataType.parse_error) {
out.type = typemap[type].default;
if (out.type === PARSE_ERROR) {
(out as MappingProperty).type = typemap[type].default;
}
out = readFieldTags(out, path, topTypeName, tags, type);
@@ -904,21 +894,21 @@ export function generateTemplate(
const templateName = `template_${typeNameWithoutSpaces}`;
out[templateName] = {
mappings: handleDeclarationReflection(_interface, new Map(), '', typeName) as ElasticsearchObject,
mappings: handleDeclarationReflection(_interface, new Map(), '', typeName) as MappingObjectProperty,
settings: settings,
index_patterns: [`stapps_${typeNameWithoutSpaces}*`],
};
out[templateName].mappings.properties.creation_date = {
type: ElasticsearchDataType.date,
out[templateName].mappings!.properties!.creation_date = {
type: 'date',
};
out[templateName].mappings.dynamic_templates = dynamicTemplates;
out[templateName].mappings!.dynamic_templates = dynamicTemplates;
// Set some properties
out[templateName].mappings._source = {
out[templateName].mappings!._source = {
excludes: ['creation_date'],
};
out[templateName].mappings.date_detection = false;
out[templateName].mappings!.date_detection = false;
dynamicTemplates = [];

View File

@@ -35,7 +35,7 @@ export function getProjectReflection(sourcePath: PathLike, excludeExternals = tr
app.bootstrap({
excludeExternals: excludeExternals,
ignoreCompilerErrors: false, // TODO: true
ignoreCompilerErrors: true,
includeDeclarations: true,
module: ModuleKind.CommonJS,
target: ScriptTarget.Latest,

341
src/types/mapping.d.ts vendored
View File

@@ -1,341 +0,0 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
/*
* Copyright (C) 2019-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 {ElasticsearchDataType} from '../config/typemap';
import {AggregationSchema} from './aggregation';
// tslint:disable:no-any
/**
* Template output of the mapping generation
*/
export interface MappingGenTemplate {
/**
* All generated aggregations
*/
aggregations: AggregationSchema;
/**
* All errors that occurred
*/
errors: string[];
/**
* All mappings that were generated
*/
mappings: ElasticsearchTemplateCollection;
}
/**
* ElasticsearchValue can be either a type or an object.
*
* Both are composed similarly, and can be the value of a property
* of an Elasticsearch Object.
*/
export type ElasticsearchValue = ElasticsearchType | ElasticsearchObject | ElasticsearchGeoShape;
/**
* The Typemap is used to get the corresponding ElasticsearchDataType for a name provided by the ProjectReflection
*/
export interface ElasticsearchTypemap {
/**
* The `stringLiteral` type must always be provided
*/
stringLiteral: {
/**
* The default can be chosen freely, but must be provided
*/
default: ElasticsearchDataType;
};
/**
* The name of the JS type, so for `number` it would be number
*/
[name: string]: {
/**
* The default ElasticsearchDataType that should be used, if no tag or only not implemented tags are found
*/
default: ElasticsearchDataType;
/**
* The name of the tag, so for `@integer` it would be `integer`
*/
[name: string]: ElasticsearchDataType;
};
}
/**
* The representation of a `DynamicTemplate` in Elasticsearch
*
* https://www.elastic.co/guide/en/elasticsearch/reference/5.6/dynamic-templates.html
*/
export interface ElasticsearchDynamicTemplate {
/**
* The name of the dynamicTemplate
*/
[name: string]: {
/**
* The mapping of the template
*/
mapping: ElasticsearchValue;
/**
* With automatic mapping, we use `path_match` more or less out of convenience and because it is least error-prone
*
* This also means that match should match all ("*") interface names (because we provide the exact path of the
* interface)
*/
match: '*';
/**
* With automatic mapping, we use `path_match` more or less out of convenience and because it is least error-prone
*
* This also means that match_mapping_type should match all ("*") names (because we provide the exact path of the
* interface)
*/
match_mapping_type: '*';
/**
* With automatic mapping, we use `path_match` more or less out of convenience and because it is least error-prone
*/
path_match: string;
};
}
export interface ElasticsearchFilterableMap {
[name: string]: ElasticsearchDataType;
}
/**
* The Fieldmap contains all tag names for fields and the corresponding fields
*
* The Fieldmap works in a similar fashion to the Typemap
*/
export interface ElasticsearchFieldmap {
/**
* The name of the tag, so for `@sortable` it would be `sortable`
*/
[name: string]: {
/**
* The default value if no parameter is provided
*/
default: {
/**
* To allow the usage of `prev.fields = {...prev.fields, ...fieldmap[tag.tagName].default}`
*
* We could also have used `default: any`, but this adds slightly more improved type-safety.
*/
[name: string]: any;
};
/**
* The tag parameters that will be ignored
*
* Some tag parameters might not be important for your implementation, so you can add their names here to not get
* any errors. The `default` will be used in that case.
*/
ignore: string[];
/**
* The parameters of the tag, so for `@sortable ducet` it would be `ducet`
*/
[name: string]: {
/**
* To allow the usage of `prev.fields = {...prev.fields, ...fieldmap[tag.tagName][tag.text.trim()]}`
*
* We could also have used `default: any`, but this adds slightly more improved type-safety.
*/
[name: string]: any;
};
};
}
/**
* A primitive data type
*
* https://www.elastic.co/guide/en/elasticsearch/reference/5.6/mapping-types.html
*/
export interface ElasticsearchType {
/**
* Fields for a type
*
* The fields are optional, they are used for things like sorting, which is not needed for every single type.
*/
fields?: {
[name: string]: any;
};
/**
* The type as an ElasticsearchDataType
*/
type: ElasticsearchDataType;
}
/**
* A GeoShape data type
*
* https://www.elastic.co/guide/en/elasticsearch/reference/5.6/geo-shape.html
*/
export interface ElasticsearchGeoShape {
/**
* Does not exist; here for TypeScript compiler
*/
fields?: undefined;
/**
* This parameter may be used instead of tree_levels to set an appropriate value for the tree_levels parameter.
*
* The value specifies the desired precision and Elasticsearch will calculate the best tree_levels value to honor
* this precision. The value should be a number followed by an optional distance unit. Valid distance units include:
* in, inch, yd, yard, mi, miles, km, kilometers, m,meters, cm,centimeters, mm, millimeters.
*/
precision: string;
/**
* Name of the PrefixTree implementation to be used: geohash for GeohashPrefixTree and quadtree for QuadPrefixTree.
*/
tree: 'quadtree' | 'geohash';
/**
* The type of the object, obviously geo_shape
*/
type: ElasticsearchDataType.geo_shape;
}
/**
* An object data type
*
* https://www.elastic.co/guide/en/elasticsearch/reference/5.6/object.html
*/
export interface ElasticsearchObject {
/**
* Only for the top type
*/
_source?: {
/**
* Fields that should be excluded in the _source field
*/
excludes: ['creation_date'];
};
/**
* Whether the creation date should be set automatically
*/
date_detection?: boolean;
/**
* If the object is a dynamic
*
* https://www.elastic.co/guide/en/elasticsearch/reference/5.6/dynamic.html
* The default should be `'strict'`
*/
dynamic: true | false | 'strict';
/**
* dynamic_templates for an object
*
* https://www.elastic.co/guide/en/elasticsearch/reference/5.6/dynamic-templates.html
* This is a more complex topic, before touching this you should really know what you are doing.
*/
dynamic_templates?: ElasticsearchDynamicTemplate[];
/**
* Fields for a type
*
* The fields are optional, they are used for things like sorting, which is not needed for every single type.
*/
fields?: {
[name: string]: any;
};
/**
* Any properties of the object
*
* https://www.elastic.co/guide/en/elasticsearch/reference/5.6/properties.html
*/
properties: {
/**
* Each property can be any Elasticsearch value
*
* https://www.elastic.co/guide/en/elasticsearch/reference/5.6/mapping-types.html
*/
[name: string]: ElasticsearchValue;
};
}
/**
* A collection of Elasticsearch Templates
*/
export interface ElasticsearchTemplateCollection {
[indexName: string]: ElasticsearchTemplate;
}
/**
* An Elasticsearch template
*
* https://www.elastic.co/guide/en/elasticsearch/reference/5.6/mapping.html
* This is what you pass to Elasticsearch
*/
export interface ElasticsearchTemplate {
/**
* The name of the template, for referencing in Elasticsearch
*/
index_patterns: [string];
/**
* This is a pre-defined structure you should use for your mapping
*/
mappings: ElasticsearchObject;
/**
* The settings for Elasticsearch
*/
settings: ElasticsearchSettings;
}
/**
* A representation of ElasticsearchSettings used in Mappings
*/
export interface ElasticsearchSettings {
/**
* The settings
*/
[name: string]: any;
/**
* This is where any analyzers go
*
* https://www.elastic.co/guide/en/elasticsearch/reference/5.6/analysis-analyzers.html
*/
analysis?: {
[name: string]: any;
};
}
/**
* A premap for a specific value in a ProjectReflection
*
* This is meant to be used for external types. To aid performance, you usually should not include external libs in the
* ProjectReflection. This means that there is no way the generator can generate a mapping for it, so you can use the
* premaps to map out a type manually.
*/
export interface ElasticsearchPremap {
/**
* The name of the type with the corresponding map
*
* So for `const a: B` the name would be `B`
*/
[name: string]: ElasticsearchValue;
}

119
src/types/mapping.ts Normal file
View File

@@ -0,0 +1,119 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import {IndicesPutTemplateRequest, MappingProperty} from '@elastic/elasticsearch/lib/api/types';
/*
* Copyright (C) 2019-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 {AggregationSchema} from './aggregation';
/**
* Template output of the mapping generation
*/
export interface MappingGenTemplate {
/**
* All generated aggregations
*/
aggregations: AggregationSchema;
/**
* All errors that occurred
*/
errors: string[];
/**
* All mappings that were generated
*/
mappings: ElasticsearchTemplateCollection;
}
export type SimpleType = MappingProperty['type'] &
('keyword' | 'float' | 'boolean' | 'date' | 'integer' | 'text');
/**
* The Typemap is used to get the corresponding ElasticsearchDataType for a name provided by the ProjectReflection
*/
export interface ElasticsearchTypemap {
/**
* The `stringLiteral` type must always be provided
*/
stringLiteral: {
/**
* The default can be chosen freely, but must be provided
*/
default: SimpleType;
};
/**
* The name of the JS type, so for `number` it would be number
*/
[name: string]: {
/**
* The default ElasticsearchDataType that should be used, if no tag or only not implemented tags are found
*/
default: SimpleType;
/**
* The name of the tag, so for `@integer` it would be `integer`
*/
[name: string]: SimpleType;
};
}
/**
* The Fieldmap contains all tag names for fields and the corresponding fields
*
* The Fieldmap works in a similar fashion to the Typemap
*/
export interface ElasticsearchFieldmap {
/**
* The name of the tag, so for `@sortable` it would be `sortable`
*/
[name: string]: {
/**
* The default value if no parameter is provided
*/
default: {
/**
* To allow the usage of `prev.fields = {...prev.fields, ...fieldmap[tag.tagName].default}`
*
* We could also have used `default: any`, but this adds slightly more improved type-safety.
*/
[name: string]: any;
};
/**
* The tag parameters that will be ignored
*
* Some tag parameters might not be important for your implementation, so you can add their names here to not get
* any errors. The `default` will be used in that case.
*/
ignore: string[];
/**
* The parameters of the tag, so for `@sortable ducet` it would be `ducet`
*/
[name: string]: {
/**
* To allow the usage of `prev.fields = {...prev.fields, ...fieldmap[tag.tagName][tag.text.trim()]}`
*
* We could also have used `default: any`, but this adds slightly more improved type-safety.
*/
[name: string]: any;
};
};
}
/**
* A collection of Elasticsearch Templates
*/
export type ElasticsearchTemplateCollection = Record<string, Omit<IndicesPutTemplateRequest, 'name'>>;

View File

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

View File

@@ -12,8 +12,7 @@
* 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 {ElasticsearchDynamicTemplate, ElasticsearchValue} from '../../src/types/mapping';
import {MappingDynamicTemplate, MappingProperty} from '@elastic/elasticsearch/lib/api/types';
export interface MapAggTestOptions {
testName: string;
@@ -29,7 +28,7 @@ export interface MapAggTestOptions {
export interface MinimalMappingDescription {
maps?: {
[name: string]: ElasticsearchValue;
[name: string]: MappingProperty;
};
dynamicTemplates?: ElasticsearchDynamicTemplate[];
dynamicTemplates?: Record<string, MappingDynamicTemplate>[];
}

View File

@@ -12,7 +12,6 @@
* 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 {generateTemplate} from '../../src/mapping';
import path from 'path';
import {expect} from 'chai';
@@ -121,10 +120,10 @@ export class MapAggTest {
};
const maps = map.maps ?? {};
maps.type = {
type: ElasticsearchDataType.text,
type: 'text',
};
maps.creation_date = {
type: ElasticsearchDataType.date,
type: 'date',
};
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore can be used to index

View File

@@ -12,10 +12,8 @@
* 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';
import {ElasticsearchDataType} from '../../../../src/config/typemap';
/**
* @date
@@ -42,10 +40,10 @@ export const testConfig: MapAggTestOptions = {
map: {
maps: {
directDate: {
type: ElasticsearchDataType.date,
type: 'date',
},
dateAlias: {
type: ElasticsearchDataType.date,
type: 'date',
},
},
},

View File

@@ -12,8 +12,7 @@
* 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 {PARSE_ERROR} from '../../../../lib/config/typemap';
import {ThingType} from './types';
import {MapAggTestOptions} from '../../map-agg-test-options';
@@ -39,7 +38,7 @@ export const testConfig: MapAggTestOptions = {
dynamic: 'strict',
properties: {
bar: {
type: ElasticsearchDataType.parse_error,
type: PARSE_ERROR,
},
},
},

View File

@@ -12,8 +12,7 @@
* 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 {TYPE_CONFLICT} from '../../../../lib/config/typemap';
import {ThingType} from './types';
import {MapAggTestOptions} from '../../map-agg-test-options';
@@ -42,10 +41,10 @@ export const testConfig: MapAggTestOptions = {
map: {
maps: {
stringDoubleTypeConflict: {
type: ElasticsearchDataType.type_conflict,
type: TYPE_CONFLICT,
},
numberDoubleTypeConflict: {
type: ElasticsearchDataType.type_conflict,
type: TYPE_CONFLICT,
},
},
},

View File

@@ -12,10 +12,8 @@
* 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';
import {ElasticsearchDataType} from '../../../../src/config/typemap';
/**
* @indexable
@@ -49,10 +47,10 @@ export const testConfig: MapAggTestOptions = {
map: {
maps: {
foo: {
type: ElasticsearchDataType.text,
type: 'text',
},
bar: {
type: ElasticsearchDataType.text,
type: 'text',
},
},
},

View File

@@ -12,10 +12,8 @@
* 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';
import {ElasticsearchDataType} from '../../../../src/config/typemap';
export type FilterableEnumType = 'a' | 'b' | 'c';
@@ -54,34 +52,34 @@ export const testConfig: MapAggTestOptions = {
map: {
maps: {
foo: {
type: ElasticsearchDataType.text,
type: 'text',
fields: {
raw: {
type: ElasticsearchDataType.keyword,
type: 'keyword',
},
},
},
bar: {
type: ElasticsearchDataType.keyword,
type: 'keyword',
fields: {
raw: {
type: ElasticsearchDataType.keyword,
type: 'keyword',
},
},
},
baz: {
type: ElasticsearchDataType.keyword,
type: 'keyword',
fields: {
raw: {
type: ElasticsearchDataType.keyword,
type: 'keyword',
},
},
},
buz: {
type: ElasticsearchDataType.keyword,
type: 'keyword',
fields: {
raw: {
type: ElasticsearchDataType.keyword,
type: 'keyword',
},
},
},

View File

@@ -12,10 +12,8 @@
* 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';
import {ElasticsearchDataType} from '../../../../src/config/typemap';
/**
* @indexable
@@ -44,7 +42,7 @@ export const testConfig: MapAggTestOptions = {
dynamic: 'strict',
properties: {
bar: {
type: ElasticsearchDataType.integer,
type: 'integer',
},
},
},
@@ -52,7 +50,7 @@ export const testConfig: MapAggTestOptions = {
dynamic: 'strict',
properties: {
bar: {
type: ElasticsearchDataType.text,
type: 'text',
},
},
},

View File

@@ -12,10 +12,8 @@
* 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';
import {ElasticsearchDataType} from '../../../../src/config/typemap';
/**
* @indexable
@@ -32,7 +30,7 @@ export const testConfig: MapAggTestOptions = {
map: {
maps: {
foo: {
type: ElasticsearchDataType.boolean,
type: 'boolean',
},
},
},

View File

@@ -12,10 +12,8 @@
* 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';
import {ElasticsearchDataType} from '../../../../src/config/typemap';
/**
* @indexable
@@ -50,16 +48,16 @@ export const testConfig: MapAggTestOptions = {
map: {
maps: {
keywordNumber: {
type: ElasticsearchDataType.integer,
type: 'integer',
},
textNumber: {
type: ElasticsearchDataType.integer,
type: 'integer',
},
integerString: {
type: ElasticsearchDataType.text,
type: 'text',
},
floatString: {
type: ElasticsearchDataType.text,
type: 'text',
},
},
},

View File

@@ -12,10 +12,8 @@
* 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';
import {ElasticsearchDataType} from '../../../../src/config/typemap';
/**
* @indexable
@@ -48,10 +46,10 @@ export const testConfig: MapAggTestOptions = {
dynamic: 'strict',
properties: {
bar: {
type: ElasticsearchDataType.integer,
type: 'integer',
},
baz: {
type: ElasticsearchDataType.text,
type: 'text',
},
},
},

View File

@@ -12,8 +12,6 @@
* 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 '../../map-agg-test-options';
import {ThingType} from './types';
@@ -45,15 +43,15 @@ export const testConfig: MapAggTestOptions = {
map: {
maps: {
foo: {
type: ElasticsearchDataType.date,
type: 'date',
fields: {
raw: {
type: ElasticsearchDataType.keyword,
type: 'keyword',
},
},
},
bar: {
type: ElasticsearchDataType.date,
type: 'date',
},
},
},

View File

@@ -12,8 +12,6 @@
* 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 '../../map-agg-test-options';
import {ThingType} from './types';
@@ -42,13 +40,13 @@ export const testConfig: MapAggTestOptions = {
map: {
maps: {
foo: {
type: ElasticsearchDataType.float,
type: 'float',
},
bar: {
dynamic: 'strict',
properties: {
baz: {
type: ElasticsearchDataType.float,
type: 'float',
},
},
},

View File

@@ -12,10 +12,8 @@
* 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';
import {ElasticsearchDataType} from '../../../../src/config/typemap';
/**
* @indexable
@@ -44,13 +42,13 @@ export const testConfig: MapAggTestOptions = {
map: {
maps: {
foo: {
type: ElasticsearchDataType.integer,
type: 'integer',
},
bar: {
type: ElasticsearchDataType.keyword,
type: 'keyword',
},
baz: {
type: ElasticsearchDataType.float,
type: 'float',
},
},
},

View File

@@ -13,10 +13,8 @@
* 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';
import {ElasticsearchDataType} from '../../../../src/config/typemap';
/**
* @indexable
@@ -36,7 +34,7 @@ export const testConfig: MapAggTestOptions = {
map: {
maps: {
foo: {
type: ElasticsearchDataType.text,
type: 'text',
},
},
},

View File

@@ -12,10 +12,8 @@
* 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';
import {ElasticsearchDataType} from '../../../../src/config/typemap';
/**
* @indexable
@@ -60,22 +58,22 @@ export const testConfig: MapAggTestOptions = {
map: {
maps: {
esInteger: {
type: ElasticsearchDataType.integer,
type: 'integer',
},
esFloat: {
type: ElasticsearchDataType.float,
type: 'float',
},
esKeyword: {
type: ElasticsearchDataType.keyword,
type: 'keyword',
},
esText: {
type: ElasticsearchDataType.text,
type: 'text',
},
esEpochMsDate: {
type: ElasticsearchDataType.date,
type: 'date',
},
esStringDate: {
type: ElasticsearchDataType.date,
type: 'date',
},
},
},

View File

@@ -12,10 +12,9 @@
* 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';
import {ElasticsearchDataType} from '../../../../src/config/typemap';
/**
* @indexable
@@ -35,7 +34,7 @@ export const testConfig: MapAggTestOptions = {
map: {
maps: {
foo: {
type: ElasticsearchDataType.missing_premap,
type: MISSING_PREMAP,
},
},
},

View File

@@ -12,10 +12,8 @@
* 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';
import {ElasticsearchDataType} from '../../../../src/config/typemap';
/**
* @indexable
@@ -52,15 +50,15 @@ export const testConfig: MapAggTestOptions = {
dynamic: 'strict',
properties: {
depth3_1: {
type: ElasticsearchDataType.integer,
type: 'integer',
},
depth3_2: {
type: ElasticsearchDataType.keyword,
type: 'keyword',
},
},
},
depth2_2: {
type: ElasticsearchDataType.boolean,
type: 'boolean',
},
},
},

View File

@@ -12,10 +12,8 @@
* 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';
import {ElasticsearchDataType} from '../../../../src/config/typemap';
/**
* @indexable
@@ -49,13 +47,13 @@ export const testConfig: MapAggTestOptions = {
dynamic: 'strict',
properties: {
a: {
type: ElasticsearchDataType.boolean,
type: 'boolean',
},
b: {
type: ElasticsearchDataType.integer,
type: 'integer',
},
intersection: {
type: ElasticsearchDataType.text,
type: 'text',
},
},
},

View File

@@ -12,10 +12,8 @@
* 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';
import {ElasticsearchDataType} from '../../../../src/config/typemap';
/**
* @indexable
@@ -43,25 +41,26 @@ export const testConfig: MapAggTestOptions = {
map: {
maps: {
foo: {
type: ElasticsearchDataType.keyword,
type: 'keyword',
fields: {
raw: {
type: ElasticsearchDataType.keyword,
type: 'keyword',
},
},
},
bar: {
type: ElasticsearchDataType.text,
type: 'text',
fields: {
raw: {
type: ElasticsearchDataType.keyword,
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

@@ -12,10 +12,8 @@
* 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';
import {ElasticsearchDataType} from '../../../../src/config/typemap';
/**
* @indexable
@@ -37,22 +35,22 @@ export const testConfig: MapAggTestOptions = {
map: {
maps: {
numberDefault: {
type: ElasticsearchDataType.integer,
type: 'integer',
},
stringDefault: {
type: ElasticsearchDataType.text,
type: 'text',
},
booleanDefault: {
type: ElasticsearchDataType.boolean,
type: 'boolean',
},
stringLiteralDefault: {
type: ElasticsearchDataType.keyword,
type: 'keyword',
},
booleanTrueLiteralDefault: {
type: ElasticsearchDataType.boolean,
type: 'boolean',
},
booleanFalseLiteralDefault: {
type: ElasticsearchDataType.boolean,
type: 'boolean',
},
},
},

View File

@@ -12,10 +12,8 @@
* 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';
import {ElasticsearchDataType} from '../../../../src/config/typemap';
/**
* @indexable
@@ -45,36 +43,39 @@ export const testConfig: MapAggTestOptions = {
map: {
maps: {
foo: {
type: ElasticsearchDataType.text,
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: ElasticsearchDataType.text,
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: ElasticsearchDataType.integer,
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

@@ -14,7 +14,6 @@
*/
import {ThingType} from './types';
import {MapAggTestOptions} from '../../map-agg-test-options';
import {ElasticsearchDataType} from '../../../../src/config/typemap';
/**
* @indexable
@@ -46,16 +45,16 @@ export const testConfig: MapAggTestOptions = {
map: {
maps: {
camelCase: {
type: ElasticsearchDataType.float,
type: 'float',
},
lowerCase: {
type: ElasticsearchDataType.float,
type: 'float',
},
bar: {
dynamic: 'strict',
properties: {
baz: {
type: ElasticsearchDataType.float,
type: 'float',
},
},
},

View File

@@ -12,10 +12,8 @@
* 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';
import {ElasticsearchDataType} from '../../../../src/config/typemap';
/**
* @indexable
@@ -55,13 +53,13 @@ export const testConfig: MapAggTestOptions = {
map: {
maps: {
textProperty: {
type: ElasticsearchDataType.text,
type: 'text',
},
keywordProperty: {
type: ElasticsearchDataType.keyword,
type: 'keyword',
},
overriddenTextAsKeyword: {
type: ElasticsearchDataType.keyword,
type: 'keyword',
},
},
},

View File

@@ -12,10 +12,8 @@
* 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';
import {ElasticsearchDataType} from '../../../../src/config/typemap';
export interface SCISO8601DateRange {
bar: string;
@@ -36,7 +34,7 @@ export const testConfig: MapAggTestOptions = {
map: {
maps: {
foo: {
type: ElasticsearchDataType.date_range,
type: 'date_range',
},
},
},

View File

@@ -12,10 +12,8 @@
* 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';
import {ElasticsearchDataType} from '../../../../src/config/typemap';
/**
* @indexable
@@ -39,7 +37,7 @@ export const testConfig: MapAggTestOptions = {
map: {
maps: {
foo: {
type: ElasticsearchDataType.text,
type: 'text',
},
},
},

View File

@@ -12,10 +12,8 @@
* 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';
import {ElasticsearchDataType} from '../../../../src/config/typemap';
/**
* @indexable
@@ -53,13 +51,13 @@ export const testConfig: MapAggTestOptions = {
dynamic: 'strict',
properties: {
numberWrapper: {
type: ElasticsearchDataType.float,
type: 'float',
},
stringWrapper: {
type: ElasticsearchDataType.keyword,
type: 'keyword',
},
stringLiteralWrapper: {
type: ElasticsearchDataType.text,
type: 'text',
},
},
},

View File

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

View File

@@ -17,6 +17,7 @@
"noUnusedParameters": true,
"outDir": "./lib/",
"strict": true,
"skipLibCheck": true,
"target": "es6"
},
"exclude": [

4
tsconfig.spec.json Normal file
View File

@@ -0,0 +1,4 @@
{
"extends": "./tsconfig.json",
"exclude": ["./lib/", "./src/"]
}