diff --git a/bin/server b/bin/server index 374f2c1..ba3ce0a 100755 --- a/bin/server +++ b/bin/server @@ -31,8 +31,7 @@ const { testValue } = require("@validatem/core"); const matchesFormat = require("@validatem/matches-format"); const isString = require("@validatem/is-string"); -const initialize = require("../src/initialize"); -const errors = require("../src/errors"); +const createKernel = require("../src/kernel"); let argv = yargs.argv; let configurationPath = argv._[0]; @@ -43,20 +42,8 @@ let absoluteConfigurationPath = path.join(process.cwd(), configurationPath); let configuration = require(absoluteConfigurationPath); return Promise.try(() => { - // FIXME: Deduplicate this with kernel! Also other common wiring across binaries... - return initialize({ - knexfile: { - client: "pg", - connection: configuration.database, - pool: { min: 0, max: 32 }, - migrations: { tableName: "srap_knex_migrations" } - } - }); -}).then((state) => { - let { db, knex } = state; - - const queries = require("../src/queries")(state); - + return createKernel(configuration); +}).then((kernel) => { let app = express(); let router = expressPromiseRouter(); @@ -125,7 +112,7 @@ return Promise.try(() => { : undefined; return pipe([ - queries.getUpdates(knex, { prefix: req.query.prefix, timestamp: timestamp }), + kernel.getUpdates({ prefix: req.query.prefix, timestamp }), map((item) => JSON.stringify(item) + "\n"), fromNodeStream(res) ]).read(); diff --git a/src/kernel.js b/src/kernel.js index 11fb7d0..1e53542 100644 --- a/src/kernel.js +++ b/src/kernel.js @@ -126,6 +126,9 @@ module.exports = async function createKernel(_configuration) { metrics: metrics }; }); + }, + getUpdates: function ({ prefix, timestamp }) { + return backend.topLevel.getUpdateStream(null, { prefix, timestamp }); } }; };