@hediet/linkrpc-cli 0.0.3-next.20261026.6 → 0.0.3-next.20261027.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/README.md CHANGED
@@ -669,12 +669,21 @@ LINKRPC_ENDPOINT=unix:/run/hub/hub.sock?token=abc linkrpc ls
669
669
  | `schema check-compat <interfaceId> <local.json>` | Compare a live interface schema with a local schema. |
670
670
  | `codegen --input <bundle> --interface <id> --name <name> --output <file> [--preserve-wire-schema] [--check]` | Generate a TypeScript interface definition from a validated offline static bundle. |
671
671
  | `codegen --input <contract> --output <file> [--names <json>] [--check]` | Generate all reusable interface definitions and typed root/service/default/bare bindings. |
672
+ | `codegen --service <id> [--max-depth <n>] ... --output <file> [--check]` | Same as above, but reflect the live service (like `contract export --service`) instead of reading a bundle. |
672
673
 
673
674
  `codegen` uses the same `{ interfaceSchemas, services?, defaultInterface?, bareInterfaces? }`
674
675
  bundle parser and interface-hash verification as static reflection. `--check`
675
676
  compares the generated source with the output file and exits unsuccessfully if
676
677
  the file is missing or stale; it never overwrites in check mode.
677
678
 
679
+ `--input` and `--service` are mutually exclusive. `--service <id>` runs the same
680
+ reflection as `contract export --service <id>` in memory (with the same failure
681
+ rules, see below) and feeds the result to codegen, so no intermediate bundle file is
682
+ needed. `--max-depth` is only valid with `--service` and defaults to unlimited;
683
+ because discovery fails rather than truncating, a single service rarely needs it.
684
+ `--check` works with `--service` too, to detect when a checked-in file drifted from
685
+ the live service.
686
+
678
687
  ```sh
679
688
  linkrpc --endpoint-cmd-stdio "node server.js" contract export --output contract.json
680
689
  linkrpc codegen --input contract.json --output generated.ts
@@ -682,6 +691,9 @@ linkrpc codegen --input contract.json --output generated.ts --check
682
691
  # Existing per-interface generation remains available:
683
692
  linkrpc codegen --input contract.json --interface demo.echo --name echoInterface \
684
693
  --output echo.ts --preserve-wire-schema
694
+ # One step against a live hub service, without an intermediate bundle:
695
+ linkrpc hub codegen --service hediet/pc2/stream-deck --interface hediet.streamDeck \
696
+ --name streamDeckInterface --output streamDeck.ts
685
697
  ```
686
698
 
687
699
  Omit both `--interface` and `--name` for whole-contract generation. Every interface
@@ -1915,12 +1915,16 @@ function formatVerdict(v) {
1915
1915
  //#endregion
1916
1916
  //#region src/commands/codegen.ts
1917
1917
  async function codegenCommand(options) {
1918
- if (/^https?:\/\//i.test(options.input)) throw new Error("codegen --input must be a local offline bundle");
1918
+ const { source } = options;
1919
+ if (source.kind === "input" && /^https?:\/\//i.test(source.path)) throw new Error("codegen --input must be a local offline bundle");
1919
1920
  if (options.name !== void 0 && !/^[$A-Z_a-z][$\w]*$/.test(options.name)) throw new Error(`codegen --name must be a valid TypeScript identifier, got '${options.name}'`);
1920
- const bundle = await loadStaticHubSchema(options.input);
1921
+ if (options.interfaceId === void 0 && options.name !== void 0) throw new Error("codegen --name requires --interface");
1922
+ if (options.interfaceId !== void 0 && options.name === void 0) throw new Error("codegen --interface requires --name");
1923
+ if (options.interfaceId !== void 0 && options.names !== void 0) throw new Error("codegen --names is only supported for whole contracts");
1924
+ const bundle = source.kind === "input" ? await loadStaticHubSchema(source.path) : await source.load();
1925
+ const sourceLabel = source.kind === "input" ? `bundle '${source.path}'` : `service '${source.serviceId}'`;
1921
1926
  let generated;
1922
1927
  if (options.interfaceId === void 0) {
1923
- if (options.name !== void 0) throw new Error("codegen --name requires --interface");
1924
1928
  let naming = {};
1925
1929
  if (options.names !== void 0) {
1926
1930
  const raw = JSON.parse(await readFile(options.names, "utf8"));
@@ -1930,11 +1934,9 @@ async function codegenCommand(options) {
1930
1934
  }
1931
1935
  generated = generateTsContract(bundle, naming);
1932
1936
  } else {
1933
- if (options.name === void 0) throw new Error("codegen --interface requires --name");
1934
- if (options.names !== void 0) throw new Error("codegen --names is only supported for whole contracts");
1935
1937
  const matches = bundle.interfaceSchemas.filter((schema) => schema.id === options.interfaceId);
1936
- if (matches.length === 0) throw new Error(`Interface '${options.interfaceId}' was not found in bundle '${options.input}'`);
1937
- if (matches.length > 1) throw new Error(`Interface '${options.interfaceId}' is ambiguous in bundle '${options.input}' (${matches.length} schema versions)`);
1938
+ if (matches.length === 0) throw new Error(`Interface '${options.interfaceId}' was not found in ${sourceLabel}`);
1939
+ if (matches.length > 1) throw new Error(`Interface '${options.interfaceId}' is ambiguous in ${sourceLabel} (${matches.length} schema versions)`);
1938
1940
  generated = generateTsInterface(matches[0], {
1939
1941
  exportName: options.name,
1940
1942
  preserveWireSchema: options.preserveWireSchema === true
@@ -1956,8 +1958,15 @@ async function codegenCommand(options) {
1956
1958
  }
1957
1959
  //#endregion
1958
1960
  //#region src/commands/contract.ts
1961
+ /** Reflects the endpoint (or one service) into a static contract; shared by `contract export` and `codegen --service`. */
1962
+ function exportContract(channel, options) {
1963
+ return exportStaticHubSchema(channel, {
1964
+ serviceId: options.serviceId,
1965
+ maxDepth: options.maxDepth
1966
+ });
1967
+ }
1959
1968
  async function exportContractCommand(channel, options) {
1960
- const document = await exportStaticHubSchema(channel, options);
1969
+ const document = await exportContract(channel, options);
1961
1970
  const text = `${JSON.stringify(document, null, 2)}\n`;
1962
1971
  if (options.output === "-") process.stdout.write(text);
1963
1972
  else {
@@ -8850,7 +8859,7 @@ async function main(rawArgv, executableName = "linkrpc") {
8850
8859
  await createAndSelectContext(preparedNewContext.reference);
8851
8860
  pendingNewContext = void 0;
8852
8861
  }
8853
- endpoint = commandUsesEndpoint(commandPath) || hasEndpointOverrides(cliOverrides) ? resolveInvocationEndpoint(g_invocation, actionCommand.name() === "tunnel") : void 0;
8862
+ endpoint = commandUsesEndpoint(commandPath, actionCommand.opts()) || hasEndpointOverrides(cliOverrides) ? resolveInvocationEndpoint(g_invocation, actionCommand.name() === "tunnel") : void 0;
8854
8863
  g_hubConfigPath = g_invocation.values.config;
8855
8864
  g_logMessages = program.opts().logMessages === true && actionCommand.name() !== "ui";
8856
8865
  g_logTransport = program.opts().logTransport === true && actionCommand.name() !== "ui";
@@ -9037,9 +9046,28 @@ async function main(rawArgv, executableName = "linkrpc") {
9037
9046
  process.stdout.write(out + "\n");
9038
9047
  });
9039
9048
  });
9040
- program.command("codegen").description("Generate reusable TypeScript interfaces and bindings from an offline contract.").requiredOption("--input <bundle>", "local static hub schema bundle").option("--interface <id>", "generate only this interface (requires --name)").option("--name <name>", "single-interface exported TypeScript const name").option("--names <file>", "whole-contract JSON interfaceNames/bindingNames overrides").requiredOption("--output <file>", "generated TypeScript output file").option("--preserve-wire-schema", "freeze the canonical input schema verbatim in the generated definition").option("--check", "fail if the output is missing or stale without overwriting it").action(async (opts) => {
9049
+ program.command("codegen").description("Generate reusable TypeScript interfaces and bindings from an offline contract bundle (--input) or directly from a live service (--service).").option("--input <bundle>", "local static hub schema bundle (exclusive with --service)").option("--service <id>", "reflect this live service like `contract export --service` (exclusive with --input)").option("--max-depth <depth>", "with --service: maximum directory referral depth (default: unlimited)", parseMaxDepth).option("--interface <id>", "generate only this interface (requires --name)").option("--name <name>", "single-interface exported TypeScript const name").option("--names <file>", "whole-contract JSON interfaceNames/bindingNames overrides").requiredOption("--output <file>", "generated TypeScript output file").option("--preserve-wire-schema", "freeze the canonical input schema verbatim in the generated definition").option("--check", "fail if the output is missing or stale without overwriting it").action(async (opts) => {
9050
+ if (opts.input === void 0 === (opts.service === void 0)) throw new InvalidArgumentError("codegen requires exactly one of --input <bundle> or --service <id>");
9051
+ if (opts.maxDepth !== void 0 && opts.service === void 0) throw new InvalidArgumentError("codegen --max-depth requires --service");
9052
+ const serviceId = opts.service;
9041
9053
  await codegenCommand({
9042
- input: opts.input,
9054
+ source: serviceId === void 0 ? {
9055
+ kind: "input",
9056
+ path: opts.input
9057
+ } : {
9058
+ kind: "service",
9059
+ serviceId,
9060
+ load: async () => {
9061
+ let document;
9062
+ await withChannel(endpoint, getPrincipalSpec(), async (channel) => {
9063
+ document = await exportContract(channel, {
9064
+ serviceId,
9065
+ maxDepth: opts.maxDepth
9066
+ });
9067
+ }, { requestReflectionAccess: true });
9068
+ return document;
9069
+ }
9070
+ },
9043
9071
  interfaceId: opts.interface,
9044
9072
  name: opts.name,
9045
9073
  output: opts.output,
@@ -9048,10 +9076,7 @@ async function main(rawArgv, executableName = "linkrpc") {
9048
9076
  names: opts.names
9049
9077
  });
9050
9078
  });
9051
- program.command("contract").description("Export reusable static interface and binding contracts.").command("export").requiredOption("--output <file>", "contract JSON destination, or - for stdout").option("--service <id>", "reflection scope (defaults to the endpoint root)").option("--max-depth <depth>", "maximum directory referral depth", (value) => {
9052
- if (!/^\d+$/.test(value)) throw new InvalidArgumentError("depth must be a non-negative integer");
9053
- return Number(value);
9054
- }).action(async (opts) => {
9079
+ program.command("contract").description("Export reusable static interface and binding contracts.").command("export").requiredOption("--output <file>", "contract JSON destination, or - for stdout").option("--service <id>", "reflection scope (defaults to the endpoint root)").option("--max-depth <depth>", "maximum directory referral depth", parseMaxDepth).action(async (opts) => {
9055
9080
  await withChannel(endpoint, getPrincipalSpec(), async (channel) => {
9056
9081
  await exportContractCommand(channel, {
9057
9082
  output: opts.output,
@@ -9663,7 +9688,7 @@ Batch options:
9663
9688
  process.once("SIGINT", onSignal);
9664
9689
  process.once("SIGTERM", onSignal);
9665
9690
  try {
9666
- const { runApprovalUi } = await import("./runApprovalUi-BckJzjKE.js");
9691
+ const { runApprovalUi } = await import("./runApprovalUi-DAJaqvdo.js");
9667
9692
  await runApprovalUi({
9668
9693
  client,
9669
9694
  signal: stop.signal
@@ -9678,7 +9703,7 @@ Batch options:
9678
9703
  registerViewCommands(program, (action) => withChannel(endpoint, getPrincipalSpec(), action));
9679
9704
  program.command("ui").description("Launch the terminal UI (form-based browser of services + methods).").action(async () => {
9680
9705
  const acquired = await acquireConnection(endpoint);
9681
- const { runUi } = await import("./runUi-BqnbXI0v.js");
9706
+ const { runUi } = await import("./runUi-CR74VSr1.js");
9682
9707
  try {
9683
9708
  await runUi({
9684
9709
  endpoint: acquired.ep,
@@ -9920,8 +9945,13 @@ function getCommandPath(command) {
9920
9945
  for (let cursor = command; cursor?.parent !== null; cursor = cursor.parent) names.unshift(cursor.name());
9921
9946
  return names.join(" ");
9922
9947
  }
9923
- function commandUsesEndpoint(commandPath) {
9924
- return !(commandPath === "context" || commandPath.startsWith("context ") || commandPath === "codegen" || commandPath === "schema hash" || commandPath === "completions" || commandPath === "_complete" || commandPath === "_connection-broker" || commandPath === "serve" || commandPath === "logout");
9948
+ function parseMaxDepth(value) {
9949
+ if (!/^\d+$/.test(value)) throw new InvalidArgumentError("depth must be a non-negative integer");
9950
+ return Number(value);
9951
+ }
9952
+ function commandUsesEndpoint(commandPath, options) {
9953
+ if (commandPath === "codegen") return options.service !== void 0;
9954
+ return !(commandPath === "context" || commandPath.startsWith("context ") || commandPath === "schema hash" || commandPath === "completions" || commandPath === "_complete" || commandPath === "_connection-broker" || commandPath === "serve" || commandPath === "logout");
9925
9955
  }
9926
9956
  function hasEndpointOverrides(values) {
9927
9957
  return values.endpoint !== void 0 || values.endpointCmd !== void 0 || values.endpointCmdStdio !== void 0 || values.endpointCmdEnv !== void 0 || values.endpointToken !== void 0 || values.endpointCmdCwd !== void 0 || values.provisionIdentity !== void 0 || values.provisionIdentitySlot !== void 0;
@@ -10241,4 +10271,4 @@ function safeJson(value) {
10241
10271
  //#endregion
10242
10272
  export { formatCondition as _, formatCommandLegend as a, targetId as b, safeTerminalText as c, ObservablePromise as d, observableValue as f, resolveViewTarget as g, Disposable as h, dispatchHostKey as i, approvalDetailLines as l, derived as m, views as n, hostCommands as o, autorun as p, ViewFrame as r, matchesKey as s, runCli as t, ObservableLazyPromise as u, interfaceTarget as v, matchesTarget as y };
10243
10273
 
10244
- //# sourceMappingURL=cli-BGl-tdAG.js.map
10274
+ //# sourceMappingURL=cli-CeXRuTXb.js.map