@cosyte/cli 0.0.1 → 0.0.3

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.
@@ -37,7 +37,7 @@ var init_exit_codes = __esm({
37
37
  DATAERR: 65,
38
38
  /** No input: the named file does not exist or is unreadable (`EX_NOINPUT`). */
39
39
  NOINPUT: 66,
40
- /** Unavailable: a required capability is not yet built (e.g. `redact` before `@cosyte/deid`), a
40
+ /** Unavailable: a required capability is not yet wired (e.g. `redact` before `@cosyte/deid`), a
41
41
  * distinct non-zero signal that is never a fake success (`EX_UNAVAILABLE`). */
42
42
  UNAVAILABLE: 69,
43
43
  /** Internal error: an unexpected exception (a bug), distinct from a handled bad input (`EX_SOFTWARE`). */
@@ -89,8 +89,8 @@ var init_diagnostics = __esm({
89
89
  /** The BYO ConceptMap supplied to `map-codes` is not valid JSON or not a loadable FHIR ConceptMap.
90
90
  * Names the stable terminology-loader code, never the map's bytes. Exit `65`. */
91
91
  CLI_MAP_INVALID: "CLI_MAP_INVALID",
92
- /** A command whose ground-layer library is not yet built (e.g. `redact` before `@cosyte/deid`
93
- * ships). Never a fake success: a distinct, value-free "unavailable" signal. Exit `69`. */
92
+ /** A command whose ground-layer library is not yet wired (e.g. `redact` before `@cosyte/deid` is
93
+ * wired). Never a fake success: a distinct, value-free "unavailable" signal. Exit `69`. */
94
94
  CLI_NOT_IMPLEMENTED: "CLI_NOT_IMPLEMENTED",
95
95
  /** An unexpected internal error (a bug). Exit `70`. */
96
96
  CLI_INTERNAL: "CLI_INTERNAL"
@@ -253,19 +253,24 @@ function anyError(findings) {
253
253
  return findings.some((f) => ERROR_SEVERITIES.has(f.severity));
254
254
  }
255
255
  async function loadOptional(format, load) {
256
+ return loadOptionalPackage(
257
+ `the @cosyte/${format} parser is not installed; install it to use this format (it is an optional dependency)`,
258
+ load
259
+ );
260
+ }
261
+ async function loadOptionalPackage(detail, load) {
256
262
  try {
257
263
  return await load();
258
264
  } catch (e) {
259
265
  if (isModuleNotFound(e)) {
260
- throw new CliError(
261
- CLI_CODES.CLI_PARSER_UNAVAILABLE,
262
- EXIT.UNAVAILABLE,
263
- `the @cosyte/${format} parser is not installed; install it to use this format (it is an optional dependency)`
264
- );
266
+ throw new CliError(CLI_CODES.CLI_PARSER_UNAVAILABLE, EXIT.UNAVAILABLE, detail);
265
267
  }
266
268
  throw e;
267
269
  }
268
270
  }
271
+ async function loadFhir() {
272
+ return loadOptionalPackage(FHIR_UNAVAILABLE, () => import('@cosyte/fhir'));
273
+ }
269
274
  function isModuleNotFound(e) {
270
275
  if (typeof e !== "object" || e === null) return false;
271
276
  const code = "code" in e ? e.code : void 0;
@@ -284,7 +289,7 @@ async function parseFormat(format, bytes) {
284
289
  };
285
290
  }
286
291
  case "fhir": {
287
- const { parseResource, serializeResource } = await import('@cosyte/fhir');
292
+ const { parseResource, serializeResource } = await loadFhir();
288
293
  const text = decode(bytes);
289
294
  const { resource, issues } = parseResource(text);
290
295
  const model = JSON.parse(serializeResource(resource));
@@ -345,7 +350,7 @@ async function inspectFormat(format, bytes) {
345
350
  };
346
351
  }
347
352
  case "fhir": {
348
- const { parseResource, resourceType, readBundle } = await import('@cosyte/fhir');
353
+ const { parseResource, resourceType, readBundle } = await loadFhir();
349
354
  const { resource, issues } = parseResource(decode(bytes));
350
355
  const rt = resourceType(resource) ?? null;
351
356
  if (rt === "Bundle") {
@@ -455,7 +460,7 @@ async function fmtFormat(format, bytes) {
455
460
  return { output: msg.toString(), warningCount: msg.warnings.length };
456
461
  }
457
462
  case "fhir": {
458
- const { parseResource, serializeResource } = await import('@cosyte/fhir');
463
+ const { parseResource, serializeResource } = await loadFhir();
459
464
  const { resource, issues } = parseResource(decode(bytes));
460
465
  return { output: serializeResource(resource), warningCount: issues.length };
461
466
  }
@@ -493,7 +498,7 @@ async function fmtFormat(format, bytes) {
493
498
  async function validateFormat(format, bytes) {
494
499
  switch (format) {
495
500
  case "fhir": {
496
- const { parseResource, validateResource } = await import('@cosyte/fhir');
501
+ const { parseResource, validateResource } = await loadFhir();
497
502
  const { resource, issues } = parseResource(decode(bytes));
498
503
  const validation = validateResource(resource);
499
504
  const findings = [
@@ -586,7 +591,7 @@ function unsupportedInternal(format, op) {
586
591
  `format '${format}' does not support \`${op}\``
587
592
  );
588
593
  }
589
- var OP_SUPPORT, ERROR_SEVERITIES;
594
+ var OP_SUPPORT, ERROR_SEVERITIES, FHIR_UNAVAILABLE;
590
595
  var init_parsers = __esm({
591
596
  "src/core/parsers.ts"() {
592
597
  init_diagnostics();
@@ -603,6 +608,7 @@ var init_parsers = __esm({
603
608
  mllp: /* @__PURE__ */ new Set(["parse", "inspect"])
604
609
  };
605
610
  ERROR_SEVERITIES = /* @__PURE__ */ new Set(["error", "fatal"]);
611
+ 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";
606
612
  }
607
613
  });
608
614
 
@@ -779,8 +785,8 @@ async function convertCommand(args, deps2, posture = VALUE_FREE) {
779
785
  async function runConvert(bytes, posture) {
780
786
  const [{ parseHL7 }, { toFhir }, { serializeResource }] = await Promise.all([
781
787
  import('@cosyte/hl7'),
782
- import('@cosyte/transform'),
783
- import('@cosyte/fhir')
788
+ loadOptionalPackage(TRANSFORM_UNAVAILABLE, () => import('@cosyte/transform')),
789
+ loadFhir()
784
790
  ]);
785
791
  let msg;
786
792
  try {
@@ -811,12 +817,13 @@ function convertOutcome(findings) {
811
817
  `;
812
818
  return { hasError: errors > 0, report: lines.join("") + summary };
813
819
  }
814
- var CONVERT_OPTIONS, SUPPORTED_TARGET, ERROR_SEVERITIES2;
820
+ var CONVERT_OPTIONS, SUPPORTED_TARGET, ERROR_SEVERITIES2, TRANSFORM_UNAVAILABLE;
815
821
  var init_convert = __esm({
816
822
  "src/commands/convert.ts"() {
817
823
  init_diagnostics();
818
824
  init_exit_codes();
819
825
  init_input();
826
+ init_parsers();
820
827
  init_phi();
821
828
  init_wrap();
822
829
  CONVERT_OPTIONS = {
@@ -828,6 +835,7 @@ var init_convert = __esm({
828
835
  };
829
836
  SUPPORTED_TARGET = "fhir";
830
837
  ERROR_SEVERITIES2 = /* @__PURE__ */ new Set(["error", "fatal"]);
838
+ 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";
831
839
  }
832
840
  });
833
841
  async function inspectCommand(args, deps2, posture = VALUE_FREE) {
@@ -1141,7 +1149,7 @@ var init_validate = __esm({
1141
1149
  var VERSION;
1142
1150
  var init_version = __esm({
1143
1151
  "src/core/version.ts"() {
1144
- VERSION = "0.0.0";
1152
+ VERSION = "0.0.3";
1145
1153
  }
1146
1154
  });
1147
1155
 
@@ -1624,7 +1632,7 @@ init_parse();
1624
1632
  init_diagnostics();
1625
1633
 
1626
1634
  // src/core/deid.ts
1627
- var DEID_UNAVAILABLE_REASON = "redact/deid is not yet available. It delegates to @cosyte/deid, which is unpublished. The CLI ships no built-in redactor: a partial Safe-Harbor scrub over only the obvious PHI loci would leave PHI behind and present a false-safety impression, so nothing is emitted. This command will produce a de-identified copy once @cosyte/deid ships and is vetted.";
1635
+ var DEID_UNAVAILABLE_REASON = "redact/deid is not yet available. It delegates to @cosyte/deid, which the CLI does not wire yet. The CLI ships no built-in redactor: a partial Safe-Harbor scrub over only the obvious PHI loci would leave PHI behind and present a false-safety impression, so nothing is emitted. This command will produce a de-identified copy once that integration lands and is vetted.";
1628
1636
  function deidStatus() {
1629
1637
  return { available: false, reason: DEID_UNAVAILABLE_REASON };
1630
1638
  }
@@ -1672,7 +1680,7 @@ Commands:
1672
1680
  fmt <file|-> Canonically re-serialize via the parser's spec-clean serializer
1673
1681
  convert <file|-> Convert HL7 v2 \u2192 FHIR R4 via @cosyte/transform (use --to fhir)
1674
1682
  map-codes <cmap|-> Translate a code through a BYO FHIR ConceptMap via @cosyte/terminology
1675
- redact <file|-> De-identify a message (alias: deid): gated on @cosyte/deid, not yet available
1683
+ redact <file|-> De-identify a message (alias: deid): gated on @cosyte/deid, not yet wired
1676
1684
  mcp Start the stdio MCP server (agent front door; also the cosyte-mcp bin)
1677
1685
  completion <shell> Print a shell completion script (bash | zsh | fish)
1678
1686