A simple command line tool that generates TypeScript definition from ElasticSearch mappings.
npm install dts-els
usage: dts-els [--array ARRAY_PROPERTIES] [--maybe-array MAYBE_ARRAY_PROPERTIES] INTERFACE_NAME
ARRAY_PROPERTIES: Cast a property to an array of the derived type. Multiple properties are separated by comma.
MAYBE_ARRAY_PROPERTIES: Cast a property to the dervided type or an array of the type.
INTERFACE_NAME: Interface name of the definition
Assume you have jq installed:
curl -s https://raw.githubusercontent.com/elastic/examples/master/Common%20Data%20Formats/twitter/twitter_template.json | jq .mappings.tweets.properties | npx dts-els --array=entities ITweet
will print out:
export interface ITweet {
// @timestamp: date
'@timestamp': number;
// text: text
'text': string;
// user: object
'user': {
// description: text
'description': string;
};
// coordinates: object
'coordinates': {
// coordinates: geo_point
'coordinates': {
// lon: float
'lon': number;
// lat: float
'lat': number;
};
};
// entities: object
'entities': Array<{
// hashtags: object
'hashtags': {
// text: text
'text': string;
};
}>;
// retweeted_status: object
'retweeted_status': {
// text: text
'text': string;
};
}
MIT. See License file.