Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
}
});
// Support projects that don't use the new project structure.
glob.sync("models/**/*.{js,sql,sqlx}", { cwd: compileConfig.projectDir }).forEach(path => {
if (definitionPaths.indexOf(path) < 0) {
definitionPaths.push(path);
}
});
const encodedConfigBytes = dataform.GenerateIndexConfig.encode({
compileConfig,
includePaths,
definitionPaths,
// For backwards compatibility with old versions of @dataform/core.
returnOverride: compileConfig.returnOverride
}).finish();
return util.base64.encode(encodedConfigBytes, 0, encodedConfigBytes.length);
}
}
try {
// check dataformJson is valid before we try to compile
const dataformJson = fs.readFileSync(`${compileConfig.projectDir}/dataform.json`, "utf8");
const projectConfig = JSON.parse(dataformJson);
checkDataformJsonValidity({
...projectConfig,
...compileConfig.projectConfigOverride
});
} catch (e) {
throw new Error(`Compile Error: ProjectConfig ('dataform.json') is invalid. ${e}`);
}
const encodedGraphInBase64 = await CompileChildProcess.forkProcess().compile(compileConfig);
const encodedGraphBytes = new Uint8Array(util.base64.length(encodedGraphInBase64));
util.base64.decode(encodedGraphInBase64, encodedGraphBytes, 0);
const compiledGraph = dataform.CompiledGraph.decode(encodedGraphBytes);
return dataform.CompiledGraph.create({
...compiledGraph,
graphErrors: validate(compiledGraph)
});
}
export function genIndex(base64EncodedConfig: string): string {
const encodedGraphBytes = new Uint8Array(util.base64.length(base64EncodedConfig));
util.base64.decode(base64EncodedConfig, encodedGraphBytes, 0);
const config = dataform.GenerateIndexConfig.decode(encodedGraphBytes);
const includeRequires = config.includePaths
.map(path => {
return `
try { global.${utils.baseFilename(path)} = require("./${path}"); } catch (e) {
if (global.session.compileError) {
global.session.compileError(e, "${path}");
} else {
console.error('Error:', e.message, 'Path: "${path}"');
}
}`;
})
.join("\n");
const definitionRequires = config.definitionPaths
export function genIndex(base64EncodedConfig: string): string {
const encodedGraphBytes = new Uint8Array(util.base64.length(base64EncodedConfig));
util.base64.decode(base64EncodedConfig, encodedGraphBytes, 0);
const config = dataform.GenerateIndexConfig.decode(encodedGraphBytes);
const includeRequires = config.includePaths
.map(path => {
return `
try { global.${utils.baseFilename(path)} = require("./${path}"); } catch (e) {
if (global.session.compileError) {
global.session.compileError(e, "${path}");
} else {
console.error('Error:', e.message, 'Path: "${path}"');
}
}`;
})
.join("\n");
const definitionRequires = config.definitionPaths
.map(path => {
export function legacyGenIndex(base64EncodedConfig: string): string {
const encodedGraphBytes = new Uint8Array(util.base64.length(base64EncodedConfig));
util.base64.decode(base64EncodedConfig, encodedGraphBytes, 0);
const config = dataform.GenerateIndexConfig.decode(encodedGraphBytes);
const includeRequires = config.includePaths
.map(path => {
return `
try { global.${utils.baseFilename(path)} = require("./${path}"); } catch (e) {
if (global.session.compileError) {
global.session.compileError(e, "${path}");
} else {
console.error('Error:', e.message, 'Path: "${path}"');
}
}`;
})
.join("\n");
const definitionRequires = config.definitionPaths
const toUuid = function(s: string): Uint8Array {
const buf = util.newBuffer(util.base64.length(s));
util.base64.decode(s, buf, 0);
return buf;
};
const toUuid = function (s: string): Uint8Array {
const buf = util.newBuffer(util.base64.length(s));
base64.decode(s, buf, 0);
return buf;
};
public compileToBase64() {
const encodedGraphBytes = dataform.CompiledGraph.encode(this.compile()).finish();
return util.base64.encode(encodedGraphBytes, 0, encodedGraphBytes.length);
}