npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@openstapps/es-mapping-generator

v3.0.0

Published

Tool to convert TypeScript Interfaces to Elasticsearch Mappings

Downloads

10

Readme

@openstapps/es-mapping-generator

pipeline status npm license) documentation

Tools to convert and validate StAppsCore

What is the ES Mapping Generator for?

The ES Mapping Generator is for converting TypeScript interfaces to Elasticsearch mappings, with support for Integer and Float types, Dates, etc.

Why is this a separate package?

The ES Mapping Generator relies on an outdated version of TypeDoc, that can't be updated. Because of that, it then also relies on an outdated version of TypeScript, resulting in a cascade effect things that can't be updated. Because of that, we decided to isolate it to the best of our abilities.

How to use the Elasticsearch Mapping generator

The mapping generator is intended to be used by the backend directly, but it can also be used to generate these files manually.

Generating the mapping files by hand

To generate the mapping files by hand, you need a local copy of the core-tools and the core, both need to be built first. After that you can run

node lib/cli.js mapping path/to/core path/to/destination ignoredTag1,ignoredTag2,ignoredTag3

If you don't pass in any ignored tags, you will likely be prompted with errors, despite the core being absolutely correct. This is because there are some tags that are not relevant to Elasticsearch, but the program has no direct way to tell which ones simply lack an implementation and which ones can be ignored. Currently the ignored tags include minlength, pattern and see.

Generating the mapping directly from another TypeScript program

This is the more easy way, and it gives you direct access to the generated mapping as a (mostly typesafe) object. To use it, call generateTemplate, However you will first need to generate a ProjectReflection of the core you are working with. If you use the core as a dependency, you can for example use

const map = generateTemplate(
  getProjectReflection(resolve('node_modules', '@openstapps', 'core', 'src')),
  ignoredTags,
  false,
);

to generate the mappings. Note that the result object contains both a list of errors in map.errors and the actual mapping in map.template. You can also specify whether you want the generator to show any errors while generating the mappings in the console in the last parameter, true (default) being show errors and false to suppress them. That said it is very easy to replace all type: "MISSING_PREMAP", type: "PARSE_ERROR", type: "TYPE_CONFLICT" with dynamic: true (you can take these exactly like written here and run a replace over the file).

Fixing a generated mapping by hand

If you get errors when generating the mappings, the mappings might not work, however they will still be generated to the programs best efforts. Most small issues can be fixed after the mapping was generated as a temporary solution and without changing anything in the mapper's code. This however requires some understanding of how mappings work.

The output of the program can easily reach 25.000 lines, but you can find errors quickly by searching for MISSING_PREMAP, PARSE_ERROR and TYPE_CONFLICT. When you reach them you can then manually replace them with your code.

As a last resort you can also replace all errors with dynamic types, this should get the mapping working, but it is NOT RECOMMENDED as a fix other than using it locally.