@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.
package/dist/index.cjs CHANGED
@@ -4,7 +4,7 @@ var promises = require('fs/promises');
4
4
  var util = require('util');
5
5
 
6
6
  // src/core/version.ts
7
- var VERSION = "0.0.0";
7
+ var VERSION = "0.0.3";
8
8
 
9
9
  // src/core/exit-codes.ts
10
10
  var EXIT = {
@@ -20,7 +20,7 @@ var EXIT = {
20
20
  DATAERR: 65,
21
21
  /** No input: the named file does not exist or is unreadable (`EX_NOINPUT`). */
22
22
  NOINPUT: 66,
23
- /** Unavailable: a required capability is not yet built (e.g. `redact` before `@cosyte/deid`), a
23
+ /** Unavailable: a required capability is not yet wired (e.g. `redact` before `@cosyte/deid`), a
24
24
  * distinct non-zero signal that is never a fake success (`EX_UNAVAILABLE`). */
25
25
  UNAVAILABLE: 69,
26
26
  /** Internal error: an unexpected exception (a bug), distinct from a handled bad input (`EX_SOFTWARE`). */
@@ -51,8 +51,8 @@ var CLI_CODES = {
51
51
  /** The BYO ConceptMap supplied to `map-codes` is not valid JSON or not a loadable FHIR ConceptMap.
52
52
  * Names the stable terminology-loader code, never the map's bytes. Exit `65`. */
53
53
  CLI_MAP_INVALID: "CLI_MAP_INVALID",
54
- /** A command whose ground-layer library is not yet built (e.g. `redact` before `@cosyte/deid`
55
- * ships). Never a fake success: a distinct, value-free "unavailable" signal. Exit `69`. */
54
+ /** A command whose ground-layer library is not yet wired (e.g. `redact` before `@cosyte/deid` is
55
+ * wired). Never a fake success: a distinct, value-free "unavailable" signal. Exit `69`. */
56
56
  CLI_NOT_IMPLEMENTED: "CLI_NOT_IMPLEMENTED",
57
57
  /** An unexpected internal error (a bug). Exit `70`. */
58
58
  CLI_INTERNAL: "CLI_INTERNAL"
@@ -228,19 +228,25 @@ function anyError(findings) {
228
228
  return findings.some((f) => ERROR_SEVERITIES.has(f.severity));
229
229
  }
230
230
  async function loadOptional(format, load) {
231
+ return loadOptionalPackage(
232
+ `the @cosyte/${format} parser is not installed; install it to use this format (it is an optional dependency)`,
233
+ load
234
+ );
235
+ }
236
+ async function loadOptionalPackage(detail, load) {
231
237
  try {
232
238
  return await load();
233
239
  } catch (e) {
234
240
  if (isModuleNotFound(e)) {
235
- throw new CliError(
236
- CLI_CODES.CLI_PARSER_UNAVAILABLE,
237
- EXIT.UNAVAILABLE,
238
- `the @cosyte/${format} parser is not installed; install it to use this format (it is an optional dependency)`
239
- );
241
+ throw new CliError(CLI_CODES.CLI_PARSER_UNAVAILABLE, EXIT.UNAVAILABLE, detail);
240
242
  }
241
243
  throw e;
242
244
  }
243
245
  }
246
+ 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";
247
+ async function loadFhir() {
248
+ return loadOptionalPackage(FHIR_UNAVAILABLE, () => import('@cosyte/fhir'));
249
+ }
244
250
  function isModuleNotFound(e) {
245
251
  if (typeof e !== "object" || e === null) return false;
246
252
  const code = "code" in e ? e.code : void 0;
@@ -259,7 +265,7 @@ async function parseFormat(format, bytes) {
259
265
  };
260
266
  }
261
267
  case "fhir": {
262
- const { parseResource, serializeResource } = await import('@cosyte/fhir');
268
+ const { parseResource, serializeResource } = await loadFhir();
263
269
  const text = decode(bytes);
264
270
  const { resource, issues } = parseResource(text);
265
271
  const model = JSON.parse(serializeResource(resource));
@@ -320,7 +326,7 @@ async function inspectFormat(format, bytes) {
320
326
  };
321
327
  }
322
328
  case "fhir": {
323
- const { parseResource, resourceType, readBundle } = await import('@cosyte/fhir');
329
+ const { parseResource, resourceType, readBundle } = await loadFhir();
324
330
  const { resource, issues } = parseResource(decode(bytes));
325
331
  const rt = resourceType(resource) ?? null;
326
332
  if (rt === "Bundle") {
@@ -430,7 +436,7 @@ async function fmtFormat(format, bytes) {
430
436
  return { output: msg.toString(), warningCount: msg.warnings.length };
431
437
  }
432
438
  case "fhir": {
433
- const { parseResource, serializeResource } = await import('@cosyte/fhir');
439
+ const { parseResource, serializeResource } = await loadFhir();
434
440
  const { resource, issues } = parseResource(decode(bytes));
435
441
  return { output: serializeResource(resource), warningCount: issues.length };
436
442
  }
@@ -468,7 +474,7 @@ async function fmtFormat(format, bytes) {
468
474
  async function validateFormat(format, bytes) {
469
475
  switch (format) {
470
476
  case "fhir": {
471
- const { parseResource, validateResource } = await import('@cosyte/fhir');
477
+ const { parseResource, validateResource } = await loadFhir();
472
478
  const { resource, issues } = parseResource(decode(bytes));
473
479
  const validation = validateResource(resource);
474
480
  const findings = [
@@ -672,7 +678,7 @@ async function readStreamBytes(stream) {
672
678
  }
673
679
 
674
680
  // src/core/deid.ts
675
- 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.";
681
+ 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.";
676
682
  function deidStatus() {
677
683
  return { available: false, reason: DEID_UNAVAILABLE_REASON };
678
684
  }
@@ -838,11 +844,12 @@ async function convertCommand(args, deps, posture = VALUE_FREE) {
838
844
  return { stdout: `${conversion.bundleText}
839
845
  `, stderr, exit };
840
846
  }
847
+ 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";
841
848
  async function runConvert(bytes, posture) {
842
849
  const [{ parseHL7 }, { toFhir }, { serializeResource }] = await Promise.all([
843
850
  import('@cosyte/hl7'),
844
- import('@cosyte/transform'),
845
- import('@cosyte/fhir')
851
+ loadOptionalPackage(TRANSFORM_UNAVAILABLE, () => import('@cosyte/transform')),
852
+ loadFhir()
846
853
  ]);
847
854
  let msg;
848
855
  try {
@@ -1324,7 +1331,7 @@ Commands:
1324
1331
  fmt <file|-> Canonically re-serialize via the parser's spec-clean serializer
1325
1332
  convert <file|-> Convert HL7 v2 \u2192 FHIR R4 via @cosyte/transform (use --to fhir)
1326
1333
  map-codes <cmap|-> Translate a code through a BYO FHIR ConceptMap via @cosyte/terminology
1327
- redact <file|-> De-identify a message (alias: deid): gated on @cosyte/deid, not yet available
1334
+ redact <file|-> De-identify a message (alias: deid): gated on @cosyte/deid, not yet wired
1328
1335
  mcp Start the stdio MCP server (agent front door; also the cosyte-mcp bin)
1329
1336
  completion <shell> Print a shell completion script (bash | zsh | fish)
1330
1337
 
@@ -1443,6 +1450,7 @@ exports.formatsSupporting = formatsSupporting;
1443
1450
  exports.inspectCommand = inspectCommand;
1444
1451
  exports.inspectFormat = inspectFormat;
1445
1452
  exports.loadOptional = loadOptional;
1453
+ exports.loadOptionalPackage = loadOptionalPackage;
1446
1454
  exports.mapCodesCommand = mapCodesCommand;
1447
1455
  exports.parseCommand = parseCommand;
1448
1456
  exports.parseFailureResult = parseFailureResult;