1 | "use strict";
|
2 | var __importDefault = (this && this.__importDefault) || function (mod) {
|
3 | return (mod && mod.__esModule) ? mod : { "default": mod };
|
4 | };
|
5 | Object.defineProperty(exports, "__esModule", { value: true });
|
6 | const path_1 = __importDefault(require("path"));
|
7 | const child_process_1 = require("child_process");
|
8 | const byline_1 = __importDefault(require("./byline"));
|
9 | function 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 | }
|
32 | exports.getInternalDatamodelJson = getInternalDatamodelJson;
|
33 |
|
\ | No newline at end of file |