fix: make mapping of generics work correctly

fixes #27
This commit is contained in:
Wieland Schöbl
2019-11-01 14:47:02 +01:00
parent 47361d412a
commit 8f7201e2cf
4 changed files with 95 additions and 95 deletions

View File

@@ -12,15 +12,17 @@
* 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 {ElasticsearchPremap, ElasticsearchValue} from '../mapping-definitions';
import {ElasticsearchPremap} from '../mapping-definitions';
import {ElasticsearchDataType} from './typemap';
export const premaps: ElasticsearchPremap = {
CoordinateReferenceSystem: {
precision: '1m',
tree: 'quadtree',
type: ElasticsearchDataType.geo_shape,
dynamic: true,
properties: {
type: {
type: ElasticsearchDataType.keyword,
},
},
},
LineString: {
precision: '1m',
@@ -50,27 +52,9 @@ export const premaps: ElasticsearchPremap = {
type: ElasticsearchDataType.keyword,
},
value: {
dynamic: true,
properties: {},
// this is actually an 'any' type, however ES does not really support that.
type: ElasticsearchDataType.keyword,
},
},
},
};
/**
* Gets an ElasticsearchValue for a name
*
* @param name the name of the premap
*/
export function getPremap(name: string): ElasticsearchValue {
for (const premap in premaps) {
if (premap === name) {
return premaps[premap];
}
}
// tslint:disable-next-line:no-floating-promises
Logger.error(`Missing pre-map for external type ${name}`);
return {type: ElasticsearchDataType.missing_premap};
}

View File

@@ -24,23 +24,6 @@ import {ElasticsearchDataType} from './definitions/typemap';
*/
export type ElasticsearchValue = ElasticsearchType | ElasticsearchObject | ElasticsearchGeoShape;
/**
* Used internally for saving a generic value contained in a reflection
*/
export interface ReflectionGeneric {
/**
* The name of the generic
*
* For example in `<number A>` the name would be 'A'
*/
name: string;
/**
* The value of the generic
*/
value: ElasticsearchValue;
}
/**
* The Typemap is used to get the corresponding ElasicsearchDataType for a name provided by the ProjectReflection
*/
@@ -273,7 +256,24 @@ export interface ElasticsearchObject {
};
}
export type ElasticsearchMapping = ElasticsearchObject;
export interface ElasticsearchMapping {
/**
* The mappings of the index
*/
mappings: {
[name: string]: ElasticsearchObject;
};
/**
* The settings for the index
*/
settings: unknown;
/**
* The name of the index
*/
template: string;
}
// TODO: docs
export interface ElasticsearchMappings {