@karmaniverous/jeeves-meta 0.20.0-0 → 0.20.0-1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli/jeeves-meta/index.js +87 -31
- package/package.json +1 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { sleepAsync, computeInsiderKey, fetchWithTimeout, DEFAULT_PORTS, createConfigQueryHandler, createStatusHandler, getBindAddress, getServiceUrl, jeevesComponentDescriptorSchema, createConfigApplyHandler, createServiceCli } from '@karmaniverous/jeeves';
|
|
2
|
+
import { sleepAsync, computeInsiderKey, fetchWithTimeout, DEFAULT_PORTS, createConfigQueryHandler, createStatusHandler, getBindAddress, rejectWindowsDrivePath, init, WORKSPACE_CONFIG_DEFAULTS, resolveConfigValue, loadWorkspaceConfig, getServiceUrl, jeevesComponentDescriptorSchema, createConfigApplyHandler, createServiceCli } from '@karmaniverous/jeeves';
|
|
3
3
|
import { normalizePath, metaConfigSchema, META_ERROR_STATUS, updateBodySchema, META_COMPONENT, META_CATALOG, META_OPENAPI_DOCUMENT } from '@karmaniverous/jeeves-meta-core';
|
|
4
4
|
import fs, { unlinkSync, writeFileSync, existsSync, readFileSync, statSync, mkdirSync, readdirSync, watchFile } from 'node:fs';
|
|
5
5
|
import path, { join, dirname, relative, posix, sep, resolve } from 'node:path';
|
|
@@ -32742,11 +32742,61 @@ function createMetaClient(options) {
|
|
|
32742
32742
|
return Object.fromEntries(methods);
|
|
32743
32743
|
}
|
|
32744
32744
|
|
|
32745
|
+
/**
|
|
32746
|
+
* Workspace and config root for the custom CLI commands, so they can ask
|
|
32747
|
+
* jeeves where meta runs (`getServiceUrl('meta')`, which reads the core
|
|
32748
|
+
* config under the config root).
|
|
32749
|
+
*
|
|
32750
|
+
* Each root follows jeeves' shared precedence: the flag, then
|
|
32751
|
+
* `JEEVES_WORKSPACE` / `JEEVES_CONFIG_ROOT`, then `core.*` in the
|
|
32752
|
+
* workspace's `jeeves.config.json`, then the defaults (`.`, `./config`).
|
|
32753
|
+
* jeeves does not export its own resolver, so this composes the exported
|
|
32754
|
+
* `loadWorkspaceConfig()` and `resolveConfigValue()` as jeeves-runner does;
|
|
32755
|
+
* karmaniverous/jeeves#169 moves this into jeeves.
|
|
32756
|
+
*
|
|
32757
|
+
* @module cliRoots
|
|
32758
|
+
*/
|
|
32759
|
+
/**
|
|
32760
|
+
* Resolve the workspace and config root by flag, env,
|
|
32761
|
+
* `jeeves.config.json`, then default.
|
|
32762
|
+
*
|
|
32763
|
+
* @param opts - The parsed flags.
|
|
32764
|
+
* @param env - Environment to read (default `process.env`).
|
|
32765
|
+
* @returns Both roots, as given (not yet made absolute).
|
|
32766
|
+
*/
|
|
32767
|
+
function resolveRoots(opts, env = process.env) {
|
|
32768
|
+
const defaults = WORKSPACE_CONFIG_DEFAULTS.core;
|
|
32769
|
+
const workspaceSeed = resolveConfigValue(opts.workspace, env['JEEVES_WORKSPACE'], undefined, defaults.workspace).value;
|
|
32770
|
+
const file = loadWorkspaceConfig(workspaceSeed);
|
|
32771
|
+
return {
|
|
32772
|
+
workspace: resolveConfigValue(opts.workspace, env['JEEVES_WORKSPACE'], file?.core?.workspace, defaults.workspace).value,
|
|
32773
|
+
configRoot: resolveConfigValue(opts.configRoot, env['JEEVES_CONFIG_ROOT'], file?.core?.configRoot, defaults.configRoot).value,
|
|
32774
|
+
};
|
|
32775
|
+
}
|
|
32776
|
+
/**
|
|
32777
|
+
* Resolve both roots and initialise jeeves with them.
|
|
32778
|
+
*
|
|
32779
|
+
* @param opts - The parsed flags.
|
|
32780
|
+
* @param env - Environment to read (default `process.env`).
|
|
32781
|
+
*/
|
|
32782
|
+
function initRoots(opts, env = process.env) {
|
|
32783
|
+
const roots = resolveRoots(opts, env);
|
|
32784
|
+
// Check the raw values: on Linux, resolve('j:/x') hides the drive letter.
|
|
32785
|
+
rejectWindowsDrivePath('configRoot', roots.configRoot);
|
|
32786
|
+
rejectWindowsDrivePath('workspacePath', roots.workspace);
|
|
32787
|
+
init({
|
|
32788
|
+
workspacePath: resolve(roots.workspace),
|
|
32789
|
+
configRoot: resolve(roots.configRoot),
|
|
32790
|
+
});
|
|
32791
|
+
}
|
|
32792
|
+
|
|
32745
32793
|
/**
|
|
32746
32794
|
* Custom CLI commands for the jeeves-meta service, built on the SDK
|
|
32747
32795
|
* (`@karmaniverous/jeeves-meta-sdk`, Decision 187). Each command calls one
|
|
32748
32796
|
* catalog entry and prints the response as JSON; a failure prints one
|
|
32749
|
-
* error line to stderr and sets exit code 1.
|
|
32797
|
+
* error line to stderr and sets exit code 1. The service URL comes from
|
|
32798
|
+
* jeeves (`getServiceUrl('meta')`) after the workspace and config root are
|
|
32799
|
+
* resolved (`cliRoots`); `--port` overrides its port.
|
|
32750
32800
|
*
|
|
32751
32801
|
* Registered via `descriptor.customCliCommands` and added to the
|
|
32752
32802
|
* standard service CLI produced by `createServiceCli`.
|
|
@@ -32754,15 +32804,17 @@ function createMetaClient(options) {
|
|
|
32754
32804
|
* @module customCliCommands
|
|
32755
32805
|
*/
|
|
32756
32806
|
/**
|
|
32757
|
-
* The service's base URL
|
|
32807
|
+
* The service's base URL: jeeves' URL for meta, with `--port` when it is
|
|
32808
|
+
* not the default.
|
|
32758
32809
|
*
|
|
32759
|
-
* @param
|
|
32810
|
+
* @param opts - The command's options.
|
|
32760
32811
|
* @returns The base URL.
|
|
32761
32812
|
*/
|
|
32762
|
-
function serviceBaseUrl(
|
|
32813
|
+
function serviceBaseUrl(opts) {
|
|
32814
|
+
initRoots(opts);
|
|
32763
32815
|
const url = new URL(getServiceUrl('meta'));
|
|
32764
|
-
if (port !== DEFAULT_PORT_STR)
|
|
32765
|
-
url.port = port;
|
|
32816
|
+
if (opts.port !== DEFAULT_PORT_STR)
|
|
32817
|
+
url.port = opts.port;
|
|
32766
32818
|
return url.origin;
|
|
32767
32819
|
}
|
|
32768
32820
|
/**
|
|
@@ -32781,12 +32833,12 @@ function errorLine(error) {
|
|
|
32781
32833
|
* Run one command: call the service, print the result as JSON, or print
|
|
32782
32834
|
* the error line and set exit code 1.
|
|
32783
32835
|
*
|
|
32784
|
-
* @param
|
|
32836
|
+
* @param opts - The command's options.
|
|
32785
32837
|
* @param call - The SDK call.
|
|
32786
32838
|
*/
|
|
32787
|
-
async function runCommand(
|
|
32839
|
+
async function runCommand(opts, call) {
|
|
32788
32840
|
try {
|
|
32789
|
-
const data = await call(createMetaClient({ baseUrl: serviceBaseUrl(
|
|
32841
|
+
const data = await call(createMetaClient({ baseUrl: serviceBaseUrl(opts) }));
|
|
32790
32842
|
console.log(JSON.stringify(data, null, 2));
|
|
32791
32843
|
}
|
|
32792
32844
|
catch (error) {
|
|
@@ -32794,27 +32846,38 @@ async function runCommand(port, call) {
|
|
|
32794
32846
|
process.exitCode = 1;
|
|
32795
32847
|
}
|
|
32796
32848
|
}
|
|
32849
|
+
/**
|
|
32850
|
+
* Add the options every service command takes: `--port`, and the roots
|
|
32851
|
+
* jeeves resolves the service URL from (no defaults, so the environment and
|
|
32852
|
+
* `jeeves.config.json` apply when a flag is absent).
|
|
32853
|
+
*
|
|
32854
|
+
* @param cmd - The command.
|
|
32855
|
+
* @returns It.
|
|
32856
|
+
*/
|
|
32857
|
+
function withServiceOptions(cmd) {
|
|
32858
|
+
return cmd
|
|
32859
|
+
.option('-p, --port <port>', 'Service port', DEFAULT_PORT_STR)
|
|
32860
|
+
.option('-w, --workspace <path>', 'Workspace root path')
|
|
32861
|
+
.option('--config-root <path>', 'Platform config root path');
|
|
32862
|
+
}
|
|
32797
32863
|
/**
|
|
32798
32864
|
* Register all custom meta commands on the parent program.
|
|
32799
32865
|
*
|
|
32800
32866
|
* @param program - The service CLI.
|
|
32801
32867
|
*/
|
|
32802
32868
|
function registerCustomCliCommands(program) {
|
|
32803
|
-
const command = (spec, description) => program
|
|
32804
|
-
|
|
32805
|
-
|
|
32806
|
-
.option('-p, --port <port>', 'Service port', DEFAULT_PORT_STR);
|
|
32807
|
-
command('list', 'List all discovered meta entities').action((opts) => runCommand(opts.port, (meta) => meta.listMetas()));
|
|
32808
|
-
command('detail <path>', 'Show full detail for a single meta entity').action((path, opts) => runCommand(opts.port, (meta) => meta.metaDetail({ path })));
|
|
32869
|
+
const command = (spec, description) => withServiceOptions(program.command(spec).description(description));
|
|
32870
|
+
command('list', 'List all discovered meta entities').action((opts) => runCommand(opts, (meta) => meta.listMetas()));
|
|
32871
|
+
command('detail <path>', 'Show full detail for a single meta entity').action((path, opts) => runCommand(opts, (meta) => meta.metaDetail({ path })));
|
|
32809
32872
|
command('preview', 'Dry-run: preview inputs for next synthesis cycle')
|
|
32810
32873
|
.option('--path <path>', 'Specific meta path to preview')
|
|
32811
|
-
.action((opts) => runCommand(opts
|
|
32874
|
+
.action((opts) => runCommand(opts, (meta) => meta.preview(opts.path ? { path: opts.path } : {})));
|
|
32812
32875
|
command('synthesize', 'Trigger synthesis (enqueues work)')
|
|
32813
32876
|
.option('--path <path>', 'Specific meta path to synthesize')
|
|
32814
|
-
.action((opts) => runCommand(opts
|
|
32815
|
-
command('seed <path>', 'Create .meta/ directory + meta.json for a path').action((path, opts) => runCommand(opts
|
|
32816
|
-
command('unlock <path>', 'Remove .lock file from a meta entity').action((path, opts) => runCommand(opts
|
|
32817
|
-
command('abort', 'Abort the current synthesis in progress').action((opts) => runCommand(opts
|
|
32877
|
+
.action((opts) => runCommand(opts, (meta) => meta.synthesize(opts.path ? { path: opts.path } : {})));
|
|
32878
|
+
command('seed <path>', 'Create .meta/ directory + meta.json for a path').action((path, opts) => runCommand(opts, (meta) => meta.seed({ path })));
|
|
32879
|
+
command('unlock <path>', 'Remove .lock file from a meta entity').action((path, opts) => runCommand(opts, (meta) => meta.unlock({ path })));
|
|
32880
|
+
command('abort', 'Abort the current synthesis in progress').action((opts) => runCommand(opts, (meta) => meta.abort()));
|
|
32818
32881
|
command('prune', 'Prune old archive snapshots beyond maxArchive').action(() => {
|
|
32819
32882
|
// The service has no prune route yet (jeeves-meta#69); 0.19.0 called a
|
|
32820
32883
|
// missing route and failed with HTTP 404.
|
|
@@ -32824,16 +32887,9 @@ function registerCustomCliCommands(program) {
|
|
|
32824
32887
|
const queue = program
|
|
32825
32888
|
.command('queue')
|
|
32826
32889
|
.description('Queue management commands');
|
|
32827
|
-
queue
|
|
32828
|
-
|
|
32829
|
-
|
|
32830
|
-
.option('-p, --port <port>', 'Service port', DEFAULT_PORT_STR)
|
|
32831
|
-
.action((opts) => runCommand(opts.port, (meta) => meta.queue()));
|
|
32832
|
-
queue
|
|
32833
|
-
.command('clear')
|
|
32834
|
-
.description('Remove all pending items from the queue')
|
|
32835
|
-
.option('-p, --port <port>', 'Service port', DEFAULT_PORT_STR)
|
|
32836
|
-
.action((opts) => runCommand(opts.port, (meta) => meta.queueClear()));
|
|
32890
|
+
const queueCommand = (name, description) => withServiceOptions(queue.command(name).description(description));
|
|
32891
|
+
queueCommand('list', 'Show current queue state').action((opts) => runCommand(opts, (meta) => meta.queue()));
|
|
32892
|
+
queueCommand('clear', 'Remove all pending items from the queue').action((opts) => runCommand(opts, (meta) => meta.queueClear()));
|
|
32837
32893
|
}
|
|
32838
32894
|
|
|
32839
32895
|
/**
|
package/package.json
CHANGED