Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 | 45x 45x 775x 9300x 9300x 775x 775x 775x 1676x 1676x 1676x 1676x 211x 211x 1676x 775x 677x 677x 677x 677x 1x 1x 677x 775x 677x 677x 677x 677x 677x 677x 677x 677x 1x 1x 1x 1x 677x 775x 677x 677x 775x 131x 131x 131x 131x 131x 131x 131x 131x 131x 131x 775x 805x 805x 805x 805x 805x 805x 805x 805x 9660x 9660x 805x 805x 805x 805x 805x 805x 805x 775x 775x 775x 775x 775x 775x 45x | 'use strict';
module.exports = ({ core: { publicErrors: { createError, databaseError, errorCodes }, }, cachePaths: { pathsForJournal }, queries: { definitions: queries }, journal: { ingestionWarning: { groupWarnings }, }, database: { prepareDatabase, readDatabase, }, external: { fs, os, path }, }) => {
const apiDefinitions = Object.freeze(Object.fromEntries(queries.map(({ name, inputSchema }) => [
name,
{ inputs: ['journalPath', ...Object.keys(inputSchema.shape)] },
])));
const projectConfigurationError = (message) => createError(errorCodes.PROJECT_CONFIGURATION, message);
function queryDatabase(databasePath, operation) {
try {
return readDatabase(databasePath, operation);
}
catch (error) {
throw databaseError(error);
}
}
function journalPaths(journalPath) {
try {
return pathsForJournal(journalPath);
}
catch (error) {
throw projectConfigurationError(error.message);
}
}
function ensureCurrent(journalPath) {
const paths = journalPaths(journalPath);
try {
fs.mkdirSync(path.dirname(paths.databasePath), { recursive: true, mode: 0o700 });
prepareDatabase(paths.databasePath, { kind: 'file', path: paths.journalPath });
fs.chmodSync(paths.databasePath, 0o600);
return paths;
}
catch (error) {
if (Object.values(errorCodes).includes(error.code))
throw error;
throw createError(errorCodes.DATABASE, error.message);
}
}
function openJournal(journalPath) {
return journalFromDatabase(ensureCurrent(journalPath));
}
function withJournalText(content, baseDirectory, operation) {
const directory = fs.mkdtempSync(path.join(os.tmpdir(), 'ledlight-stdin-'));
try {
const databasePath = path.join(directory, 'journal.sqlite');
const { journalPath } = prepareDatabase(databasePath, { kind: 'stdin', content, baseDirectory });
return operation(journalFromDatabase({ databasePath, journalPath }));
}
finally {
fs.rmSync(directory, { recursive: true, force: true });
}
}
function journalFromDatabase(current) {
const warnings = groupWarnings(queryDatabase(current.databasePath, (database) => database.prepare(`
SELECT code, message, source, line, column,
start_line AS startLine, end_line AS endLine
FROM ingestion_warnings
ORDER BY position
`).all()));
const caches = Object.freeze({ valuationPriceCache: new Map() });
const operations = Object.fromEntries(queries.map(({ name, execute }) => [
name,
(options) => queryDatabase(current.databasePath, (database) => execute(database, options, caches)),
]));
return {
...current,
warnings,
...operations,
};
}
return {
apiDefinitions,
openJournal,
withJournalText,
$$private: { journalFromDatabase },
};
};
|