UNPKG

1.52 kBJavaScriptView Raw
1"use strict";
2var __importDefault = (this && this.__importDefault) || function (mod) {
3 return (mod && mod.__esModule) ? mod : { "default": mod };
4};
5Object.defineProperty(exports, "__esModule", { value: true });
6const path_1 = __importDefault(require("path"));
7const child_process_1 = require("child_process");
8const byline_1 = __importDefault(require("./byline"));
9function getInternalDatamodelJson(datamodel, schemaInferrerPath = path_1.default.join(__dirname, '../schema-inferrer-bin')) {
10 return new Promise((resolve, reject) => {
11 const proc = child_process_1.spawn(schemaInferrerPath, { stdio: ['pipe', 'pipe', process.stderr] });
12 proc.on('error', function (err) {
13 console.error('[schema-inferrer-bin] error: %s', err);
14 reject(err);
15 });
16 proc.on('exit', function (code, signal) {
17 if (code !== 0) {
18 console.error('[schema-inferrer-bin] exit: code=%s signal=%s', code, signal);
19 }
20 reject();
21 });
22 const out = byline_1.default(proc.stdout);
23 out.on('data', line => {
24 const result = JSON.parse(line);
25 const resultB64 = Buffer.from(JSON.stringify(result)).toString('base64');
26 resolve(resultB64);
27 });
28 const cut = datamodel.replace(/\n/g, ' ');
29 proc.stdin.write(JSON.stringify({ dataModel: cut }) + '\n');
30 });
31}
32exports.getInternalDatamodelJson = getInternalDatamodelJson;
33//# sourceMappingURL=getInternalDatamodelJson.js.map
\No newline at end of file