@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.
@@ -5,7 +5,7 @@ import { ListToolsRequestSchema, CallToolRequestSchema } from '@modelcontextprot
5
5
  import { parseArgs } from 'util';
6
6
 
7
7
  // src/core/version.ts
8
- var VERSION = "0.0.0";
8
+ var VERSION = "0.0.3";
9
9
 
10
10
  // src/core/exit-codes.ts
11
11
  var EXIT = {
@@ -21,7 +21,7 @@ var EXIT = {
21
21
  DATAERR: 65,
22
22
  /** No input: the named file does not exist or is unreadable (`EX_NOINPUT`). */
23
23
  NOINPUT: 66,
24
- /** Unavailable: a required capability is not yet built (e.g. `redact` before `@cosyte/deid`), a
24
+ /** Unavailable: a required capability is not yet wired (e.g. `redact` before `@cosyte/deid`), a
25
25
  * distinct non-zero signal that is never a fake success (`EX_UNAVAILABLE`). */
26
26
  UNAVAILABLE: 69,
27
27
  /** Internal error: an unexpected exception (a bug), distinct from a handled bad input (`EX_SOFTWARE`). */
@@ -49,8 +49,8 @@ var CLI_CODES = {
49
49
  CLI_PARSER_UNAVAILABLE: "CLI_PARSER_UNAVAILABLE",
50
50
  /** The wrapped parser rejected the input. Positional context only, never the offending bytes. Exit `65`. */
51
51
  CLI_PARSE_FAILED: "CLI_PARSE_FAILED",
52
- /** A command whose ground-layer library is not yet built (e.g. `redact` before `@cosyte/deid`
53
- * ships). Never a fake success: a distinct, value-free "unavailable" signal. Exit `69`. */
52
+ /** A command whose ground-layer library is not yet wired (e.g. `redact` before `@cosyte/deid` is
53
+ * wired). Never a fake success: a distinct, value-free "unavailable" signal. Exit `69`. */
54
54
  CLI_NOT_IMPLEMENTED: "CLI_NOT_IMPLEMENTED",
55
55
  /** An unexpected internal error (a bug). Exit `70`. */
56
56
  CLI_INTERNAL: "CLI_INTERNAL"
@@ -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") {
@@ -423,7 +429,7 @@ async function inspectFormat(format, bytes) {
423
429
  async function validateFormat(format, bytes) {
424
430
  switch (format) {
425
431
  case "fhir": {
426
- const { parseResource, validateResource } = await import('@cosyte/fhir');
432
+ const { parseResource, validateResource } = await loadFhir();
427
433
  const { resource, issues } = parseResource(decode(bytes));
428
434
  const validation = validateResource(resource);
429
435
  const findings = [
@@ -671,11 +677,12 @@ async function convertCommand(args, deps, posture = VALUE_FREE) {
671
677
  return { stdout: `${conversion.bundleText}
672
678
  `, stderr, exit };
673
679
  }
680
+ 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";
674
681
  async function runConvert(bytes, posture) {
675
682
  const [{ parseHL7 }, { toFhir }, { serializeResource }] = await Promise.all([
676
683
  import('@cosyte/hl7'),
677
- import('@cosyte/transform'),
678
- import('@cosyte/fhir')
684
+ loadOptionalPackage(TRANSFORM_UNAVAILABLE, () => import('@cosyte/transform')),
685
+ loadFhir()
679
686
  ]);
680
687
  let msg;
681
688
  try {