Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
25 lines
1.4 KiB
JavaScript
25 lines
1.4 KiB
JavaScript
/**
|
|
* hal/deps.mjs — HAL 의존성 묶음(deps) 만들기. index.mjs(운영)와 테스트가 같은 함수를 쓴다.
|
|
* deps = { store, vault, config, jobs, log, version, instanceId, serviceauth, notifyLib, fetch, emergencyRunner, jobsRunning, stopping }
|
|
*/
|
|
import { openDb } from '../lib/db.mjs';
|
|
import { openVault } from '../lib/vault.mjs';
|
|
import { createJobEngine } from '../lib/jobs.mjs';
|
|
import * as serviceauth from '../lib/serviceauth.mjs';
|
|
import * as notifyLib from '../lib/notify.mjs';
|
|
import { newId } from '../lib/crypto.mjs';
|
|
import { MIGRATIONS } from './schema.mjs';
|
|
import { registerKinds } from './jobs.mjs';
|
|
import { readFileSync } from 'node:fs';
|
|
import { join } from 'node:path';
|
|
|
|
export const VERSION = JSON.parse(readFileSync(new URL('../package.json', import.meta.url), 'utf8')).version;
|
|
export function createHalDeps({ config, dbFile = null, log = () => {}, fetchImpl = null, version = VERSION, concurrency = 64 } = {}) {
|
|
const store = openDb(dbFile || join(config.dataDir, 'hal.sqlite'), MIGRATIONS);
|
|
const vault = openVault(config.dataDir);
|
|
const d = { store, vault, config, log, version, instanceId: newId('hal_'), serviceauth, notifyLib, fetch: fetchImpl, emergencyRunner: null, jobsRunning: false, stopping: false };
|
|
d.jobs = createJobEngine(store, { log, workerId: `hal@${process.pid}`, concurrency, pollMs: 500 });
|
|
registerKinds(d.jobs, d);
|
|
return d;
|
|
}
|