@cosyte/cli 0.0.2 → 0.0.4

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/index.d.cts CHANGED
@@ -3,23 +3,30 @@ export { r as readFileBytes, a as readStreamBytes } from './io-B2EobRzC.cjs';
3
3
  import 'node:stream';
4
4
 
5
5
  /**
6
- * The CLI version string, synced with `package.json#version` on release by the Changesets `version`
7
- * script. Kept in its own module so both the programmatic entry point and the dispatcher share one
8
- * source of truth.
6
+ * The CLI version string, synced with `package.json#version` on release by `scripts/sync-version.mjs`,
7
+ * which the `version` script runs immediately after `changeset version`. Kept in its own module so
8
+ * both the programmatic entry point and the dispatcher share one source of truth.
9
+ *
10
+ * The declaration below is rewritten by that script and is matched at column 0, annotation included.
11
+ * Renaming it or reflowing it makes the script exit non-zero rather than silently no-op; the shape is
12
+ * pinned by `test/sanity.test.ts`, and the value is compared against `package.json` there too.
9
13
  *
10
14
  * @packageDocumentation
11
15
  */
12
16
  /**
13
17
  * The `@cosyte/cli` version. On the uniform `v0.0.x-until-first-alpha` ladder.
14
18
  *
19
+ * Read by `cosyte --version` and by the MCP server's advertised `SERVER_INFO`, so it is a
20
+ * user-visible surface on both front doors, not merely an export.
21
+ *
15
22
  * @example
16
23
  * ```ts
17
24
  * import { VERSION } from "@cosyte/cli";
18
25
  *
19
- * typeof VERSION; // => "string"
26
+ * console.log(`cosyte ${VERSION}`);
20
27
  * ```
21
28
  */
22
- declare const VERSION = "0.0.0";
29
+ declare const VERSION: string;
23
30
 
24
31
  /**
25
32
  * The `cosyte` CLI **exit-code contract**: a designed, documented surface that CI pipelines and
@@ -616,6 +623,33 @@ declare function valueFreeLocator(pos: unknown): string;
616
623
  * ```
617
624
  */
618
625
  declare function loadOptional<T>(format: CosyteFormat, load: () => Promise<T>): Promise<T>;
626
+ /**
627
+ * The same graceful-degradation path as {@link loadOptional}, keyed on a **package name** rather than
628
+ * a {@link CosyteFormat}, with the diagnostic supplied by the caller.
629
+ *
630
+ * Two of the packages the CLI lazy-loads are not wire-format parsers and so cannot go through
631
+ * {@link loadOptional}: `@cosyte/transform` (a conversion library, not one of the eight formats, so
632
+ * calling it a "parser" in the diagnostic would be wrong) and `@cosyte/fhir` (a format, but absent for
633
+ * a reason no reinstall fixes, which the message has to say). Both are reachable from a published
634
+ * install only if the user already has them, so both must degrade to a value-free
635
+ * `CLI_PARSER_UNAVAILABLE` (exit `69`) instead of surfacing a raw resolver error and a stack frame.
636
+ *
637
+ * @template T - The imported module's type.
638
+ * @param detail - The value-free diagnostic detail shown when the package is absent.
639
+ * @param load - A thunk performing the dynamic import.
640
+ * @returns The imported module.
641
+ * @throws {CliError} `CLI_PARSER_UNAVAILABLE` (exit `69`) when the package is absent; any other error
642
+ * propagates unchanged.
643
+ * @example
644
+ * ```ts
645
+ * import { loadOptionalPackage } from "@cosyte/cli";
646
+ *
647
+ * await loadOptionalPackage("the conversion library is not installed", () =>
648
+ * import("@cosyte/transform"),
649
+ * );
650
+ * ```
651
+ */
652
+ declare function loadOptionalPackage<T>(detail: string, load: () => Promise<T>): Promise<T>;
619
653
  /**
620
654
  * Parse one record of `format` into the wrapped library's model + its value-free warnings. The model
621
655
  * is emitted verbatim on the data channel; the CLI adds no parsing of its own.
@@ -1357,4 +1391,4 @@ declare function redactCommand(args: string[]): RunResult;
1357
1391
  */
1358
1392
  declare function completionCommand(args: string[]): RunResult;
1359
1393
 
1360
- export { CLI_CODES, type CliCode, CliError, type CosyteFormat, DEID_UNAVAILABLE_REASON, DETECTABLE_FORMATS, type DeidAvailability, type DetectResult, EXIT, type ExitCode, type Finding, type FmtResult, type InputResolution, type InspectSummary, KNOWN_FORMATS, OP_SUPPORT, type Op, type ParseResult, type ParseWarning, type PhiPosture, type ResolvedInput, RunDeps, type RunResult, SHOW_VALUES, UNSAFE_EXCERPT_MAX, UNSAFE_SHOW_VALUES_FLAG, VALUE_FREE, VERSION, type Verdict, asCosyteFormat, classifyCandidates, completionCommand, convertCommand, convertOutcome, deframeMllp, deidStatus, detectFormat, detectionError, errorResult, extractPhiPosture, extractStableCode, fmtCommand, fmtFormat, formatDiagnostic, formatHl7Position, formatsSupporting, inspectCommand, inspectFormat, loadOptional, mapCodesCommand, parseCommand, parseFailureResult, parseFormat, redactCommand, resolveInput, run, supportsOp, toCliError, unsafeInputSuffix, validateCommand, validateFormat, valueFreeLocator };
1394
+ export { CLI_CODES, type CliCode, CliError, type CosyteFormat, DEID_UNAVAILABLE_REASON, DETECTABLE_FORMATS, type DeidAvailability, type DetectResult, EXIT, type ExitCode, type Finding, type FmtResult, type InputResolution, type InspectSummary, KNOWN_FORMATS, OP_SUPPORT, type Op, type ParseResult, type ParseWarning, type PhiPosture, type ResolvedInput, RunDeps, type RunResult, SHOW_VALUES, UNSAFE_EXCERPT_MAX, UNSAFE_SHOW_VALUES_FLAG, VALUE_FREE, VERSION, type Verdict, asCosyteFormat, classifyCandidates, completionCommand, convertCommand, convertOutcome, deframeMllp, deidStatus, detectFormat, detectionError, errorResult, extractPhiPosture, extractStableCode, fmtCommand, fmtFormat, formatDiagnostic, formatHl7Position, formatsSupporting, inspectCommand, inspectFormat, loadOptional, loadOptionalPackage, mapCodesCommand, parseCommand, parseFailureResult, parseFormat, redactCommand, resolveInput, run, supportsOp, toCliError, unsafeInputSuffix, validateCommand, validateFormat, valueFreeLocator };
package/dist/index.d.ts CHANGED
@@ -3,23 +3,30 @@ export { r as readFileBytes, a as readStreamBytes } from './io-B2EobRzC.js';
3
3
  import 'node:stream';
4
4
 
5
5
  /**
6
- * The CLI version string, synced with `package.json#version` on release by the Changesets `version`
7
- * script. Kept in its own module so both the programmatic entry point and the dispatcher share one
8
- * source of truth.
6
+ * The CLI version string, synced with `package.json#version` on release by `scripts/sync-version.mjs`,
7
+ * which the `version` script runs immediately after `changeset version`. Kept in its own module so
8
+ * both the programmatic entry point and the dispatcher share one source of truth.
9
+ *
10
+ * The declaration below is rewritten by that script and is matched at column 0, annotation included.
11
+ * Renaming it or reflowing it makes the script exit non-zero rather than silently no-op; the shape is
12
+ * pinned by `test/sanity.test.ts`, and the value is compared against `package.json` there too.
9
13
  *
10
14
  * @packageDocumentation
11
15
  */
12
16
  /**
13
17
  * The `@cosyte/cli` version. On the uniform `v0.0.x-until-first-alpha` ladder.
14
18
  *
19
+ * Read by `cosyte --version` and by the MCP server's advertised `SERVER_INFO`, so it is a
20
+ * user-visible surface on both front doors, not merely an export.
21
+ *
15
22
  * @example
16
23
  * ```ts
17
24
  * import { VERSION } from "@cosyte/cli";
18
25
  *
19
- * typeof VERSION; // => "string"
26
+ * console.log(`cosyte ${VERSION}`);
20
27
  * ```
21
28
  */
22
- declare const VERSION = "0.0.0";
29
+ declare const VERSION: string;
23
30
 
24
31
  /**
25
32
  * The `cosyte` CLI **exit-code contract**: a designed, documented surface that CI pipelines and
@@ -616,6 +623,33 @@ declare function valueFreeLocator(pos: unknown): string;
616
623
  * ```
617
624
  */
618
625
  declare function loadOptional<T>(format: CosyteFormat, load: () => Promise<T>): Promise<T>;
626
+ /**
627
+ * The same graceful-degradation path as {@link loadOptional}, keyed on a **package name** rather than
628
+ * a {@link CosyteFormat}, with the diagnostic supplied by the caller.
629
+ *
630
+ * Two of the packages the CLI lazy-loads are not wire-format parsers and so cannot go through
631
+ * {@link loadOptional}: `@cosyte/transform` (a conversion library, not one of the eight formats, so
632
+ * calling it a "parser" in the diagnostic would be wrong) and `@cosyte/fhir` (a format, but absent for
633
+ * a reason no reinstall fixes, which the message has to say). Both are reachable from a published
634
+ * install only if the user already has them, so both must degrade to a value-free
635
+ * `CLI_PARSER_UNAVAILABLE` (exit `69`) instead of surfacing a raw resolver error and a stack frame.
636
+ *
637
+ * @template T - The imported module's type.
638
+ * @param detail - The value-free diagnostic detail shown when the package is absent.
639
+ * @param load - A thunk performing the dynamic import.
640
+ * @returns The imported module.
641
+ * @throws {CliError} `CLI_PARSER_UNAVAILABLE` (exit `69`) when the package is absent; any other error
642
+ * propagates unchanged.
643
+ * @example
644
+ * ```ts
645
+ * import { loadOptionalPackage } from "@cosyte/cli";
646
+ *
647
+ * await loadOptionalPackage("the conversion library is not installed", () =>
648
+ * import("@cosyte/transform"),
649
+ * );
650
+ * ```
651
+ */
652
+ declare function loadOptionalPackage<T>(detail: string, load: () => Promise<T>): Promise<T>;
619
653
  /**
620
654
  * Parse one record of `format` into the wrapped library's model + its value-free warnings. The model
621
655
  * is emitted verbatim on the data channel; the CLI adds no parsing of its own.
@@ -1357,4 +1391,4 @@ declare function redactCommand(args: string[]): RunResult;
1357
1391
  */
1358
1392
  declare function completionCommand(args: string[]): RunResult;
1359
1393
 
1360
- export { CLI_CODES, type CliCode, CliError, type CosyteFormat, DEID_UNAVAILABLE_REASON, DETECTABLE_FORMATS, type DeidAvailability, type DetectResult, EXIT, type ExitCode, type Finding, type FmtResult, type InputResolution, type InspectSummary, KNOWN_FORMATS, OP_SUPPORT, type Op, type ParseResult, type ParseWarning, type PhiPosture, type ResolvedInput, RunDeps, type RunResult, SHOW_VALUES, UNSAFE_EXCERPT_MAX, UNSAFE_SHOW_VALUES_FLAG, VALUE_FREE, VERSION, type Verdict, asCosyteFormat, classifyCandidates, completionCommand, convertCommand, convertOutcome, deframeMllp, deidStatus, detectFormat, detectionError, errorResult, extractPhiPosture, extractStableCode, fmtCommand, fmtFormat, formatDiagnostic, formatHl7Position, formatsSupporting, inspectCommand, inspectFormat, loadOptional, mapCodesCommand, parseCommand, parseFailureResult, parseFormat, redactCommand, resolveInput, run, supportsOp, toCliError, unsafeInputSuffix, validateCommand, validateFormat, valueFreeLocator };
1394
+ export { CLI_CODES, type CliCode, CliError, type CosyteFormat, DEID_UNAVAILABLE_REASON, DETECTABLE_FORMATS, type DeidAvailability, type DetectResult, EXIT, type ExitCode, type Finding, type FmtResult, type InputResolution, type InspectSummary, KNOWN_FORMATS, OP_SUPPORT, type Op, type ParseResult, type ParseWarning, type PhiPosture, type ResolvedInput, RunDeps, type RunResult, SHOW_VALUES, UNSAFE_EXCERPT_MAX, UNSAFE_SHOW_VALUES_FLAG, VALUE_FREE, VERSION, type Verdict, asCosyteFormat, classifyCandidates, completionCommand, convertCommand, convertOutcome, deframeMllp, deidStatus, detectFormat, detectionError, errorResult, extractPhiPosture, extractStableCode, fmtCommand, fmtFormat, formatDiagnostic, formatHl7Position, formatsSupporting, inspectCommand, inspectFormat, loadOptional, loadOptionalPackage, mapCodesCommand, parseCommand, parseFailureResult, parseFormat, redactCommand, resolveInput, run, supportsOp, toCliError, unsafeInputSuffix, validateCommand, validateFormat, valueFreeLocator };
package/dist/index.mjs CHANGED
@@ -2,7 +2,7 @@ import { readFile } from 'fs/promises';
2
2
  import { parseArgs } from 'util';
3
3
 
4
4
  // src/core/version.ts
5
- var VERSION = "0.0.0";
5
+ var VERSION = "0.0.4";
6
6
 
7
7
  // src/core/exit-codes.ts
8
8
  var EXIT = {
@@ -226,19 +226,25 @@ function anyError(findings) {
226
226
  return findings.some((f) => ERROR_SEVERITIES.has(f.severity));
227
227
  }
228
228
  async function loadOptional(format, load) {
229
+ return loadOptionalPackage(
230
+ `the @cosyte/${format} parser is not installed; install it to use this format (it is an optional dependency)`,
231
+ load
232
+ );
233
+ }
234
+ async function loadOptionalPackage(detail, load) {
229
235
  try {
230
236
  return await load();
231
237
  } catch (e) {
232
238
  if (isModuleNotFound(e)) {
233
- throw new CliError(
234
- CLI_CODES.CLI_PARSER_UNAVAILABLE,
235
- EXIT.UNAVAILABLE,
236
- `the @cosyte/${format} parser is not installed; install it to use this format (it is an optional dependency)`
237
- );
239
+ throw new CliError(CLI_CODES.CLI_PARSER_UNAVAILABLE, EXIT.UNAVAILABLE, detail);
238
240
  }
239
241
  throw e;
240
242
  }
241
243
  }
244
+ var FHIR_UNAVAILABLE = "the @cosyte/fhir parser is not installed, and it is not currently on the npm registry, so it cannot be installed from there; FHIR support is unavailable in this install";
245
+ async function loadFhir() {
246
+ return loadOptionalPackage(FHIR_UNAVAILABLE, () => import('@cosyte/fhir'));
247
+ }
242
248
  function isModuleNotFound(e) {
243
249
  if (typeof e !== "object" || e === null) return false;
244
250
  const code = "code" in e ? e.code : void 0;
@@ -257,7 +263,7 @@ async function parseFormat(format, bytes) {
257
263
  };
258
264
  }
259
265
  case "fhir": {
260
- const { parseResource, serializeResource } = await import('@cosyte/fhir');
266
+ const { parseResource, serializeResource } = await loadFhir();
261
267
  const text = decode(bytes);
262
268
  const { resource, issues } = parseResource(text);
263
269
  const model = JSON.parse(serializeResource(resource));
@@ -318,7 +324,7 @@ async function inspectFormat(format, bytes) {
318
324
  };
319
325
  }
320
326
  case "fhir": {
321
- const { parseResource, resourceType, readBundle } = await import('@cosyte/fhir');
327
+ const { parseResource, resourceType, readBundle } = await loadFhir();
322
328
  const { resource, issues } = parseResource(decode(bytes));
323
329
  const rt = resourceType(resource) ?? null;
324
330
  if (rt === "Bundle") {
@@ -428,7 +434,7 @@ async function fmtFormat(format, bytes) {
428
434
  return { output: msg.toString(), warningCount: msg.warnings.length };
429
435
  }
430
436
  case "fhir": {
431
- const { parseResource, serializeResource } = await import('@cosyte/fhir');
437
+ const { parseResource, serializeResource } = await loadFhir();
432
438
  const { resource, issues } = parseResource(decode(bytes));
433
439
  return { output: serializeResource(resource), warningCount: issues.length };
434
440
  }
@@ -466,7 +472,7 @@ async function fmtFormat(format, bytes) {
466
472
  async function validateFormat(format, bytes) {
467
473
  switch (format) {
468
474
  case "fhir": {
469
- const { parseResource, validateResource } = await import('@cosyte/fhir');
475
+ const { parseResource, validateResource } = await loadFhir();
470
476
  const { resource, issues } = parseResource(decode(bytes));
471
477
  const validation = validateResource(resource);
472
478
  const findings = [
@@ -836,11 +842,12 @@ async function convertCommand(args, deps, posture = VALUE_FREE) {
836
842
  return { stdout: `${conversion.bundleText}
837
843
  `, stderr, exit };
838
844
  }
845
+ var TRANSFORM_UNAVAILABLE = "the @cosyte/transform conversion library is not installed, so convert is unavailable; it requires @cosyte/fhir, which is not currently on the npm registry, so npm skips transform as an unresolvable optional dependency and installing it directly fails for the same reason";
839
846
  async function runConvert(bytes, posture) {
840
847
  const [{ parseHL7 }, { toFhir }, { serializeResource }] = await Promise.all([
841
848
  import('@cosyte/hl7'),
842
- import('@cosyte/transform'),
843
- import('@cosyte/fhir')
849
+ loadOptionalPackage(TRANSFORM_UNAVAILABLE, () => import('@cosyte/transform')),
850
+ loadFhir()
844
851
  ]);
845
852
  let msg;
846
853
  try {
@@ -1409,6 +1416,6 @@ function resolve(e) {
1409
1416
  `, exit: e.exit };
1410
1417
  }
1411
1418
 
1412
- export { CLI_CODES, CliError, DEID_UNAVAILABLE_REASON, DETECTABLE_FORMATS, EXIT, KNOWN_FORMATS, OP_SUPPORT, SHOW_VALUES, UNSAFE_EXCERPT_MAX, UNSAFE_SHOW_VALUES_FLAG, VALUE_FREE, VERSION, asCosyteFormat, classifyCandidates, completionCommand, convertCommand, convertOutcome, deframeMllp, deidStatus, detectFormat, detectionError, errorResult, extractPhiPosture, extractStableCode, fmtCommand, fmtFormat, formatDiagnostic, formatHl7Position, formatsSupporting, inspectCommand, inspectFormat, loadOptional, mapCodesCommand, parseCommand, parseFailureResult, parseFormat, readFileBytes, readStreamBytes, redactCommand, resolveInput, run, supportsOp, toCliError, unsafeInputSuffix, validateCommand, validateFormat, valueFreeLocator };
1419
+ export { CLI_CODES, CliError, DEID_UNAVAILABLE_REASON, DETECTABLE_FORMATS, EXIT, KNOWN_FORMATS, OP_SUPPORT, SHOW_VALUES, UNSAFE_EXCERPT_MAX, UNSAFE_SHOW_VALUES_FLAG, VALUE_FREE, VERSION, asCosyteFormat, classifyCandidates, completionCommand, convertCommand, convertOutcome, deframeMllp, deidStatus, detectFormat, detectionError, errorResult, extractPhiPosture, extractStableCode, fmtCommand, fmtFormat, formatDiagnostic, formatHl7Position, formatsSupporting, inspectCommand, inspectFormat, loadOptional, loadOptionalPackage, mapCodesCommand, parseCommand, parseFailureResult, parseFormat, readFileBytes, readStreamBytes, redactCommand, resolveInput, run, supportsOp, toCliError, unsafeInputSuffix, validateCommand, validateFormat, valueFreeLocator };
1413
1420
  //# sourceMappingURL=index.mjs.map
1414
1421
  //# sourceMappingURL=index.mjs.map