feat: json-schema updates\nfeat: new route proposal

This commit is contained in:
2023-11-01 14:31:12 +01:00
parent 8466976b3c
commit 0de613969e
20 changed files with 327 additions and 131 deletions

View File

@@ -40,7 +40,7 @@ export function transformProject(project: JSONSchema7) {
};
}
const OPTIONS: GeneratorOptions = {
export const OPTIONS: GeneratorOptions = {
template: {
name: 'template_{_type}',
index_patterns: 'stapps_{_type}*',

View File

@@ -1,5 +1,48 @@
import {transformProject} from './generator/index.js';
import {OPTIONS, transformProject} from './generator/index.js';
import {SchemaConsumer} from '@openstapps/json-schema-generator';
import {Plugin} from 'esbuild';
// eslint-disable-next-line unicorn/import-style
import {dirname} from 'path';
import {MappingGenerator} from './generator/mapping-generator.js';
export const esbuildElasticsearchMappingPlugin: Plugin = {
name: 'elasticsearch-mappings',
setup(build) {
const fileRegex = /^elasticsearch:/;
const namespace = 'elasticsearch-mappings-ns';
const mappings = new Map<string, string>();
build.onResolve({filter: fileRegex}, async ({path, importer}) => {
const [from, name] = path.replace(fileRegex, '').split('#', 2);
return {
path: `${
from
? await build
.resolve(from, {resolveDir: dirname(importer), kind: 'import-statement'})
.then(it => it.path)
: importer
}#${name}`,
namespace,
};
});
build.onLoad({filter: /.*/, namespace}, async ({path}) => {
if (!mappings.has(path)) {
const result = await build.resolve(`schema:${path}`, {kind: 'import-statement'});
console.log(result);
const context = new MappingGenerator(result.pluginData.schema, OPTIONS);
const name = path.split('#', 2)[1];
mappings.set(path, JSON.stringify(context.buildTemplate(name)));
}
return {
contents: mappings.get(path),
loader: 'json',
};
});
},
};
/**
* JSON Schema Generator plugin for Elasticsearch Mappings