Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions .changeset/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ A change to `docs-content/`, tests, CI, or scripts gets none, and never an empty
(`changeset add --empty`): only a changeset starts a release, and one that bumps nothing sends a
release through approval that publishes nothing.

While the version is below 1.0, every release is a **patch**, including a breaking change (a renamed or removed command,
flag, output field, exit code or diagnostic code) and new capability. Call a break out in the
changeset: say what changed and what a caller must do.
While the version is below 1.0, a release is a **patch** unless a minor has been approved for that
release by name, and a breaking change (a renamed or removed command, flag, output field, exit code
or diagnostic code) can ship in either. Call a break out in the changeset: say what changed and
what a caller must do.
27 changes: 27 additions & 0 deletions .changeset/parsers-0-2.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
---
"@cosyte/cli": minor
---

`cosyte` now runs on the 0.2 lines of `@cosyte/hl7`, `@cosyte/fhir` and `@cosyte/ccda`, with `@cosyte/transform` 0.3 and the `@cosyte/deid` and `@cosyte/mllp` releases that accept them, so a FHIR parse warning is now `{ code, position: { expression } }` with no severity, and every code those libraries pass through carries their prefix.

What a caller must change: read each row of the table below against the scripts, `jq` filters and programs that consume `cosyte` output, the `cosyte-mcp` tool results, or `parseFormat` and `validateFormat` from the programmatic API. HL7 v2, X12, ASTM, NCPDP, DICOM and C-CDA output keeps its shape; only the codes named in the second table change.

| What changes | Before | After | How to find it |
| ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------- |
| Each entry of `warnings` in `cosyte parse` output for a FHIR resource, in a `parse --ndjson` record, in the MCP `parse` result, and from `parseFormat("fhir", ...)` | `{ "code", "severity", "expression" }` | `{ "code", "position": { "expression" } }`, the shape every other format's warnings have | a `jq` filter or a program reading `.warnings[].severity` or `.warnings[].expression` on FHIR input |
| The `severity` of a `cosyte validate` finding that comes from reading a FHIR resource (not from `validateResource`), in the stderr line, in `--json`, in the MCP `validate` result, and from `validateFormat` | `information` for some codes, such as the decimal precision warning | always `warning`; the verdict and the exit code are unchanged, since neither severity fails it | `grep -rn 'information'` near a check on `validate` output, or `jq '.findings[] \| select(.severity == "information")'` |
| A code passed through from `@cosyte/hl7`, in `warnings[].code`, `findings[].code`, the parenthesized code after `CLI_PARSE_FAILED`, and a failed record's `error` | an unprefixed name, such as `NO_MSH_SEGMENT` | the same name with `HL7_` in front: `HL7_NO_MSH_SEGMENT` | `grep -rnE '"[A-Z][A-Z0-9]*(_[A-Z0-9]+)+"'` in the code that reads HL7 v2 output |
| A code passed through from `@cosyte/fhir`, in the same places | `MALFORMED_JSON`, `CODE_INVALID`, `INVARIANT_VIOLATED`, `DECIMAL_PRECISION_AT_RISK` | `FHIR_MALFORMED_JSON`, `FHIR_CODE_INVALID`, `FHIR_INVARIANT_VIOLATED`, `FHIR_DECIMAL_PRECISION_AT_RISK` | the same `grep`, in the code that reads FHIR output |
| A code passed through from `@cosyte/ccda`, in the same places | an unprefixed name, such as `NOT_WELL_FORMED_XML` | the same name with `CCDA_` in front: `CCDA_NOT_WELL_FORMED_XML` | the same `grep`, in the code that reads C-CDA output |
| An MLLP stream with a start byte (`VT`) inside a frame, read by `cosyte parse` or `cosyte inspect` | exit `0`: the bytes before the second `VT` dropped with an `MLLP_TRAILING_BYTES` framing warning, and the message after it read | exit `65`, `CLI_PARSE_FAILED` with `(MLLP_PAYLOAD_CONTAINS_VT)`: the frame is refused whole and nothing in it is read | a script that expects exit `0` or a nonzero `warningCount` from `inspect` on such a stream |

Each library's own changelog lists every renamed code. The ones the `cosyte` docs and examples use:

| Library | Before | After |
| -------------- | ------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `@cosyte/hl7` | `NO_MSH_SEGMENT`, `MSH_TOO_SHORT`, `INVALID_ENCODING_CHARACTERS`, `EMPTY_INPUT` | `HL7_NO_MSH_SEGMENT`, `HL7_MSH_TOO_SHORT`, `HL7_INVALID_ENCODING_CHARACTERS`, `HL7_EMPTY_INPUT` |
| `@cosyte/fhir` | `MALFORMED_JSON`, `CODE_INVALID`, `INVARIANT_VIOLATED`, `DECIMAL_PRECISION_AT_RISK`, `UNKNOWN_ELEMENT`, `CARDINALITY_MIN` | `FHIR_MALFORMED_JSON`, `FHIR_CODE_INVALID`, `FHIR_INVARIANT_VIOLATED`, `FHIR_DECIMAL_PRECISION_AT_RISK`, `FHIR_UNKNOWN_ELEMENT`, `FHIR_CARDINALITY_MIN` |
| `@cosyte/ccda` | `NOT_WELL_FORMED_XML`, `MISSING_DOSE_QUANTITY` | `CCDA_NOT_WELL_FORMED_XML`, `CCDA_MISSING_DOSE_QUANTITY` |
| `@cosyte/mllp` | `MLLP_TRAILING_BYTES` on a `VT` inside a frame | `MLLP_PAYLOAD_CONTAINS_VT` |

The `CLI_*` codes, the exit codes, the commands and their flags are unchanged. An install of this release takes the 0.2 lines of `@cosyte/hl7`, `@cosyte/fhir` and `@cosyte/ccda` and nothing older, so a project that also depends on one of them directly moves it to 0.2 in the same change.
4 changes: 2 additions & 2 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ pnpm check:no-internal-refs
- A floor in `quality-floor.json` only rises. Raise it with `pnpm quality:raise` after a full
mutation run (`pnpm mutate:full`), in a pull request of its own.
- A change to anything in the npm tarball (`src/`, `README.md`, or a `package.json` field npm
shows) adds a changeset (`pnpm changeset`), always a patch. A change to `docs-content/`, tests,
CI, or scripts adds none.
shows) adds a changeset (`pnpm changeset`), a patch unless a minor has been approved for that
release by name. A change to `docs-content/`, tests, CI, or scripts adds none.

## Contributing

Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ diagnostic** posture.

## Status

The 0.1 line. While the package is below 1.0, a breaking change can ship in a patch
version and is called out in the changelog. The `cosyte` command wraps **all eight
The 0.2 line. While the package is below 1.0, a breaking change can ship in a patch or a
minor version and is called out in the changelog. The `cosyte` command wraps **all eight
Cosyte formats** (**HL7 v2**, **FHIR R4**, **X12**, **ASTM**, **NCPDP SCRIPT and Telecom**, **C-CDA**, **DICOM**,
and **MLLP**) plus the `@cosyte/transform` and `@cosyte/terminology` higher-layer libraries, with
conservative content-format autodetection and a documented exit-code contract:
Expand Down Expand Up @@ -78,9 +78,9 @@ npm install -g @cosyte/cli # put `cosyte` on your PATH
Requires Node.js 22 or later, tested on 22, 24, and 26.

Versions `0.0.1` and `0.0.2` are on npm but cannot be installed, because of a packaging defect in
those releases. Install the 0.1 line.
those releases. Install the 0.2 line.

Below 1.0 a break can ship in a patch release, so a caret range such as `^0.1.0` does not protect a
Below 1.0 a break can ship in a patch release, so a caret range such as `^0.2.0` does not protect a
consumer. Pin the exact version:

```bash no-run it installs the package from npm
Expand Down
9 changes: 5 additions & 4 deletions docs-content/api/src.md
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,8 @@ A value-free positional locator: a FHIRPath expression, or an HL7 segment/field

> `readonly` **severity**: `string`

The R4-style severity (`fatal` | `error` | `warning` | `information`), or `warning` for HL7.
The R4-style severity (`fatal` | `error` | `warning` | `information`) of a FHIR validation or a
conversion finding, or `warning` for a parse warning, which carries no severity of its own.

***

Expand Down Expand Up @@ -1658,7 +1659,7 @@ extractPhiPosture(["parse", "x.hl7", "--unsafe-show-values"]).argv; // => ["pars
> **extractStableCode**(`e`): `string` \| `null`

Pull a `code` off a thrown value **only** when it is a PHI-free constant token
(`^[A-Z][A-Z0-9_]*$`: a letter-led UPPER_SNAKE code like `MALFORMED_JSON`), e.g. a wrapped
(`^[A-Z][A-Z0-9_]*$`: a letter-led UPPER_SNAKE code like `FHIR_MALFORMED_JSON`), e.g. a wrapped
parser's stable fatal code. Anything else (no `code`, a non-string, a non-token, or a **pure-digit**
value that could be a raw identifier) yields `null`, so a parser exception that embedded input bytes
in a `code`-shaped field can never reach a diagnostic.
Expand All @@ -1682,7 +1683,7 @@ The stable code token, or `null`.
```ts
import { extractStableCode } from "@cosyte/cli";

extractStableCode({ code: "MALFORMED_JSON" }); // => "MALFORMED_JSON"
extractStableCode({ code: "FHIR_MALFORMED_JSON" }); // => "FHIR_MALFORMED_JSON"
extractStableCode(new Error("boom")); // => null
```

Expand Down Expand Up @@ -2563,7 +2564,7 @@ A value-free `CLI_PARSE_FAILED` / exit-`65` [RunResult](#runresult).
import { parseFailureResult, VALUE_FREE } from "@cosyte/cli";

const bytes = new TextEncoder().encode("not hl7");
parseFailureResult("hl7", bytes, VALUE_FREE, { code: "MISSING_MSH" }).exit; // => 65
parseFailureResult("hl7", bytes, VALUE_FREE, { code: "HL7_NO_MSH_SEGMENT" }).exit; // => 65
```

***
Expand Down
2 changes: 1 addition & 1 deletion docs-content/check-messages-in-ci.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ cosyte validate messages/result.json; echo "exit $?"
```

```text
cosyte: validate: error CODE_INVALID at Observation.status
cosyte: validate: error FHIR_CODE_INVALID at Observation.status
cosyte: validate: fhir is INVALID (1 error(s), 0 other finding(s))
exit 1
```
Expand Down
4 changes: 2 additions & 2 deletions docs-content/debug-a-rejected-message.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ cosyte parse broken.json; echo "exit $?"
```

```text
cosyte: CLI_PARSE_FAILED: the fhir parser rejected the input (MALFORMED_JSON)
cosyte: CLI_PARSE_FAILED: the fhir parser rejected the input (FHIR_MALFORMED_JSON)
exit 65
```

## 1. Read the code

The code in parentheses is the parser library's own, here `@cosyte/fhir`'s `MALFORMED_JSON`. The
The code in parentheses is the parser library's own, here `@cosyte/fhir`'s `FHIR_MALFORMED_JSON`. The
library's documentation on [docs.cosyte.com](https://docs.cosyte.com) lists its codes and what each
means. The diagnostic carries no value from the message, so it is safe to paste into an issue.

Expand Down
2 changes: 1 addition & 1 deletion docs-content/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ npm install --save-dev --save-exact @cosyte/cli
npx cosyte --version
```

Below 1.0 a break can ship in a patch release, so a caret range such as `^0.1.0` does not protect
Below 1.0 a break can ship in a patch release, so a caret range such as `^0.2.0` does not protect
you. `--save-exact` writes the exact version into `package.json`; raise it yourself after reading
the changelog.

Expand Down
2 changes: 1 addition & 1 deletion docs-content/intro.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ Not every command supports every format; [Format support](./format-support.md) h

## Status

The 0.1 line is published to npm. Below 1.0, a breaking change can ship in a patch version and is
The 0.2 line is published to npm. Below 1.0, a breaking change can ship in a patch or a minor version and is
called out in the changelog. Two early versions cannot be installed at all: see
[If you are on 0.0.1 or 0.0.2](./installation.md#if-you-are-on-001-or-002).

Expand Down
2 changes: 1 addition & 1 deletion docs-content/mcp-tools.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ A `validate` call on a Patient whose `gender` is not in its value set:
"data": {
"format": "fhir",
"valid": false,
"findings": [{ "code": "CODE_INVALID", "severity": "error", "location": "Patient.gender" }]
"findings": [{ "code": "FHIR_CODE_INVALID", "severity": "error", "location": "Patient.gender" }]
}
}
```
Expand Down
4 changes: 2 additions & 2 deletions docs-content/parse-messages-in-a-pipeline.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ cosyte parse --format fhir message.hl7; echo "exit $?"
```

```text
cosyte: CLI_PARSE_FAILED: the fhir parser rejected the input (MALFORMED_JSON)
cosyte: CLI_PARSE_FAILED: the fhir parser rejected the input (FHIR_MALFORMED_JSON)
exit 65
```

Expand Down Expand Up @@ -96,7 +96,7 @@ echo "exit ${PIPESTATUS[0]}"

```text
{"record":0,"error":null,"resourceType":"Patient"}
{"record":1,"error":"MALFORMED_JSON","resourceType":null}
{"record":1,"error":"FHIR_MALFORMED_JSON","resourceType":null}
{"record":2,"error":null,"resourceType":"Observation"}
exit 65
```
Expand Down
2 changes: 1 addition & 1 deletion docs-content/quickstart.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ cosyte validate patient.json; echo "exit $?"
```

```text
cosyte: validate: error CODE_INVALID at Patient.gender
cosyte: validate: error FHIR_CODE_INVALID at Patient.gender
cosyte: validate: fhir is INVALID (1 error(s), 0 other finding(s))
exit 1
```
Expand Down
2 changes: 1 addition & 1 deletion docs-content/use-the-programmatic-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ const deps = {
const result = await run(["validate", "patient.json"], deps);
result.exit === EXIT.INVALID; // => true
result.stdout; // => ""
result.stderr.split("\n")[0]; // => "cosyte: validate: error CODE_INVALID at Patient.gender"
result.stderr.split("\n")[0]; // => "cosyte: validate: error FHIR_CODE_INVALID at Patient.gender"
```

To read real files, pass `readFileBytes` as `readFile`: it applies the same size limit as the
Expand Down
2 changes: 1 addition & 1 deletion examples/exit-codes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ for (const [name, run] of Object.entries(results)) {

assert.equal(valid.status, 0);
assert.equal(invalid.status, 1);
assert.match(invalid.stderr, /CODE_INVALID at Patient\.gender/);
assert.match(invalid.stderr, /FHIR_CODE_INVALID at Patient\.gender/);
assert.equal(usage.status, 2);
assert.equal(unparseable.status, 65);
assert.match(unparseable.stderr, /CLI_FORMAT_UNDETECTED/);
Expand Down
14 changes: 7 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@
"@cosyte/prettier-config": "^0.1.2",
"@cosyte/process": "^0.1.10",
"@cosyte/script-utils": "^0.1.17",
"@cosyte/synth": "^0.1.5",
"@cosyte/synth": "^0.1.16",
"@cosyte/test-utils": "^0.1.4",
"@cosyte/tsconfig": "^0.1.2",
"@cosyte/tsup-config": "^0.1.3",
Expand All @@ -165,18 +165,18 @@
"vitest": "5.1.0"
},
"dependencies": {
"@cosyte/hl7": "^0.1.10",
"@cosyte/hl7": "^0.2.0",
"@cosyte/terminology": "^0.2.0"
},
"optionalDependencies": {
"@cosyte/astm": "^0.2.0",
"@cosyte/ccda": "^0.1.6",
"@cosyte/deid": "^0.2.4",
"@cosyte/ccda": "^0.2.0",
"@cosyte/deid": "^0.2.20",
"@cosyte/dicom": "^0.2.0",
"@cosyte/fhir": "^0.1.11",
"@cosyte/mllp": "^0.1.9",
"@cosyte/fhir": "^0.2.0",
"@cosyte/mllp": "^0.1.17",
"@cosyte/ncpdp": "^0.2.0",
"@cosyte/transform": "^0.2.2",
"@cosyte/transform": "^0.3.0",
"@cosyte/x12": "^0.2.0",
"@modelcontextprotocol/sdk": "^1.32.2"
}
Expand Down
Loading
Loading