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
6 changes: 5 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,9 @@ jobs:
# (`pnpm check:docs-content`, script-utils' `cosyte-docs-content`: the sidebar, each page's kind,
# the one limitations page in Reference, page ids, held at the counts its ratchet records, and,
# with cosyte-docs-content.config.json, no README or page sample that prints a value identifying
# a person). `documents` is a required context: the `ci-required-checks` ruleset in the banner
# a person), and the generated API reference in docs-content/api/ against what
# `cosyte-docs-reference` writes from the source (`pnpm check:docs-reference`, from
# @cosyte/process). `documents` is a required context: the `ci-required-checks` ruleset in the banner
# above names it.
documents:
runs-on: ubuntu-latest
Expand All @@ -177,3 +179,5 @@ jobs:
run: pnpm check:process
- name: docs-content follows the docs-content standard, and no sample prints an identifying value
run: pnpm check:docs-content
- name: The generated API reference in docs-content/api matches the source
run: pnpm check:docs-reference
3 changes: 3 additions & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ pnpm check:claude-card
pnpm check:catalog
pnpm check:process
pnpm check:docs-content
pnpm check:docs-reference
# no-emdash and no-internal-refs
pnpm check:no-emdash
pnpm check:no-internal-refs
Expand All @@ -76,6 +77,8 @@ pnpm check:no-internal-refs
name what the caller chose (a command, flag, format, or path), never what the input held.
`--unsafe-show-values` is the one opt-in, off by default. A change to an output path adds a test
that a planted synthetic value does not appear without that flag.
- After a change to an export or its TSDoc, run `pnpm docs:reference` and commit the pages in
`docs-content/api/` with it: `pnpm check:docs-reference` fails on a stale page.
- After an intended change to the export surface, run `pnpm build` and then
`pnpm api-surface --all --write`, and commit `release/public-api.json` and
`release/public-api-mcp.json` with it: a test fails when a fresh build differs from the record.
Expand Down
186 changes: 179 additions & 7 deletions docs-content/api/src.md
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,67 @@ How many parse warnings the round-trip surfaced (value-free count only).

***

### OutputSink

The stdout side of the `cosyte` bin, from [createOutputSink](#createoutputsink): every chunk of the data channel
goes through [OutputSink.write](#write), which waits for the consumer and keeps count of what it was
owed.

#### Properties

##### delivered

> `readonly` **delivered**: `boolean`

Whether every write was acknowledged without an error and the stream is still open.

##### open

> `readonly` **open**: `boolean`

Whether the stream is still open: no error and no close seen.

##### produced

> `readonly` **produced**: `boolean`

Whether anything was written (or attempted) at all.

#### Methods

##### flushed()

> **flushed**(): `Promise`\<`void`\>

Resolve once every queued write has been acknowledged or has failed, or the stream has closed.

###### Returns

`Promise`\<`void`\>

##### write()

> **write**(`chunk`): `Promise`\<`void`\> \| `undefined`

Queue `chunk` on the stream. Returns a promise when the stream's buffer is full, which settles
when the stream drains (or closes, or fails): the caller writes nothing more until then.

###### Parameters

###### chunk

`string`

###### Returns

`Promise`\<`void`\> \| `undefined`

###### Throws

When the stream has already closed or failed: nothing more can be delivered.

***

### ParseResult

The result of wrapping a parser's `parse`: the library's parsed model + its value-free warnings.
Expand Down Expand Up @@ -442,12 +503,18 @@ Read all of stdin's bytes.

##### writeStdout?

> `readonly` `optional` **writeStdout?**: (`chunk`) => `void`
> `readonly` `optional` **writeStdout?**: (`chunk`) => `unknown`

Optional: write one piece of the data channel **as it is produced**. When present, a multi-record
`parse` writes each record's NDJSON line through here instead of accumulating them, and the
returned result's `stdout` is empty because the output has already been delivered. May throw (a
consumer that closed the pipe); the caller turns that into a value-free
Optional: write one piece of the data channel **as it is produced**. When present, `parse` writes
its output through here instead of returning it: each record's NDJSON line on a multi-record
input, and a single message's JSON in bounded pieces, and the returned result's `stdout` is empty
because the output has already been delivered.

Returning a promise says the consumer is behind (the stream's buffer is full): no more output is
produced, and no more input read for it, until the promise settles. [createOutputSink](#createoutputsink)
returns one exactly when the stream asks for a `drain`. Any other return value is ignored, so a
sink written as `(chunk) => lines.push(chunk)` still fits. May throw, or return a promise that
rejects (a consumer that closed the pipe); the caller turns either into a value-free
`CLI_OUTPUT_WRITE_FAILED`.

###### Parameters
Expand All @@ -458,7 +525,7 @@ consumer that closed the pipe); the caller turns that into a value-free

###### Returns

`void`
`unknown`

***

Expand Down Expand Up @@ -888,6 +955,14 @@ process.exitCode = EXIT.OK; // => 0

***

### JSON\_CHUNK\_CHARS

> `const` **JSON\_CHUNK\_CHARS**: `number`

The piece size [jsonChunks](#jsonchunks) aims for: 64 Ki characters, a pipe buffer's worth or so.

***

### KNOWN\_FORMATS

> `const` **KNOWN\_FORMATS**: readonly [`CosyteFormat`](#cosyteformat)[]
Expand Down Expand Up @@ -978,7 +1053,7 @@ The default, safe posture: no value ever reaches a secondary surface.

### VERSION

> `const` **VERSION**: `string` = `"0.1.7"`
> `const` **VERSION**: `string` = `"0.1.13"`

The `@cosyte/cli` version. On the uniform `v0.0.x-until-first-alpha` ladder.

Expand Down Expand Up @@ -1228,6 +1303,48 @@ convertOutcome([{ code: "TRANSFORM_ELEMENT_DROPPED", severity: "information", lo

***

### createOutputSink()

> **createOutputSink**(`stream`): [`OutputSink`](#outputsink)

Wrap a writable stream (`process.stdout` in the bin) as an [OutputSink](#outputsink) that honours
back-pressure: when `stream.write` says its buffer is full, the write hands back a promise that
settles on `drain`, so the producer stops instead of queueing its whole output in memory.

It also answers the delivery question a closed pipe raises. A consumer that closes the pipe makes
a later write fail, which the stream reports asynchronously, so a run whose writes were all queued
before that report would look delivered. Every chunk is therefore owed an acknowledgement, and
[OutputSink.delivered](#delivered) is true only when each one came back clean.

#### Parameters

##### stream

`WritableStream`

The stream to write to.

#### Returns

[`OutputSink`](#outputsink)

The sink.

#### Example

```ts
import { PassThrough } from "node:stream";
import { createOutputSink } from "@cosyte/cli";

const out = new PassThrough();
const sink = createOutputSink(out);
await sink.write("{}\n");
await sink.flushed();
sink.delivered; // => true
```

***

### deframeMllp()

> **deframeMllp**(`bytes`): `Promise`\<\{ `payloads`: `Buffer`\<`ArrayBufferLike`\>[]; `warningCount`: `number`; \}\>
Expand Down Expand Up @@ -1993,6 +2110,61 @@ isDeidCovered("x12"); // => true

***

### jsonChunks()

> **jsonChunks**(`value`, `space?`, `size?`): `Generator`\<`string`\>

Write `value` as JSON, a piece at a time: the pieces joined are exactly
`JSON.stringify(value, null, space)`.

Each piece is at least `size` characters (but the last) and rarely much more: one escaped slice of
a long string, or one short scalar, past it. A piece is handed out as soon as it is full, so a
consumer that writes each one before asking for the next never holds more than a piece of the
text at once.

#### Parameters

##### value

`unknown`

The value to write. A value `JSON.stringify` would write as `undefined` writes
nothing.

##### space?

`number`

The indentation, as `JSON.stringify` takes it: a number of spaces (at most 10), or
none for compact output.

##### size?

`number` = `JSON_CHUNK_CHARS`

The piece size to aim for. Defaults to [JSON\_CHUNK\_CHARS](#json_chunk_chars).

#### Returns

`Generator`\<`string`\>

The text's pieces, in order.

#### Throws

Where `JSON.stringify` throws: a cycle, or a `BigInt`.

#### Example

```ts
import { jsonChunks } from "@cosyte/cli";

[...jsonChunks({ resourceType: "Patient", active: true })].join("");
// => '{"resourceType":"Patient","active":true}'
```

***

### loadOptional()

> **loadOptional**\<`T`\>(`format`, `load`): `Promise`\<`T`\>
Expand Down
9 changes: 6 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@
"check:claude-card": "cosyte-claude-card",
"check:catalog": "cosyte-catalog",
"check:docs-content": "cosyte-docs-content",
"check:docs-reference": "cosyte-docs-reference --check",
"docs:reference": "cosyte-docs-reference",
"check:process": "cosyte-process check",
"lint": "cosyte-process lint",
"lint:fix": "cosyte-process lint --fix",
Expand Down Expand Up @@ -122,7 +124,7 @@
"pack:docs": "cosyte-process pack-docs",
"attw": "cosyte-attw",
"api-surface": "cosyte-api-surface",
"version": "changeset version && node scripts/sync-version.mjs && cosyte-process format",
"version": "changeset version && node scripts/sync-version.mjs && cosyte-docs-reference && cosyte-process format",
"release": "changeset publish",
"prepublishOnly": "pnpm clean && pnpm typecheck && pnpm lint && pnpm test && pnpm build && pnpm attw",
"prepare": "command -v simple-git-hooks >/dev/null 2>&1 && simple-git-hooks 1>&2 || true"
Expand All @@ -135,7 +137,8 @@
"esbuild@>=0.27.3 <0.28.2": "0.28.2",
"js-yaml@>=4.0.0 <4.3.2": "4.3.2",
"js-yaml@>=3.0.0 <3.15.2": "3.15.2",
"minimatch@>=10.0.0 <11.0.1": "11.0.1"
"minimatch@>=10.0.0 <11.0.1": "11.0.1",
"typedoc>minimatch": "10.2.6"
}
},
"devDependencies": {
Expand All @@ -144,7 +147,7 @@
"@cosyte/bench": "^0.1.1",
"@cosyte/eslint-config": "^0.1.4",
"@cosyte/prettier-config": "^0.1.2",
"@cosyte/process": "^0.1.7",
"@cosyte/process": "^0.1.10",
"@cosyte/script-utils": "^0.1.16",
"@cosyte/synth": "^0.1.5",
"@cosyte/test-utils": "^0.1.4",
Expand Down
Loading
Loading