> ## Documentation Index
> Fetch the complete documentation index at: https://docs.bijection.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Generate, continue and release reports

> Render reports from your own functions, continue when they are ready, and release them through a declared release.

> [!NOTE]
>
> These examples describe the current Bijection CLI and SDK source. Use builds
> from the same source commit for these APIs. The public CLI and npm SDK
> are published independently and may lag this reference.

This page assumes the documents library is placed at `docs` with a
`renderer`, as in [generate your first document](https://docs.bijection.com/files/documents/quickstart.md).

## Generate from your own function

`docs.helpers.generate(ctx, request, { then })` writes the report
`rendering` and submits its render task in your transaction, with the
bytes of the images it draws (at most 50, 8 MiB in all). The request names
a `space`, the `formats` (`pdf`, `docx`, `pptx`, `csv`, `images`) and either
a `doc`, whose current text is compiled with each embed captured by your
`capture` adapters, or a `document` your app composed with `report` from
`@bijectionhq/library-documents`.

With `then`, the helper also submits a task to `docs.ready`, which settles
when the report does: `{ report, state: "ready" | "failed", digest, error }`.
Your continuation is the next step of the flow.

```ts bijection/briefs.ts theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
import { mutation, t } from "@bijectionhq/bijection";
import { docs, releaser, workspace } from "./app";
import { briefs } from "./schema";

export const render = mutation(
  { under: workspace, allow: [releaser], args: { brief: t.key(briefs) } },
  async (ctx, { brief }) => {
    const fact = await ctx.get(briefs(brief));
    if (fact === null) return ctx.refuse("Absent", "no such brief.");
    return await docs.helpers.generate(
      ctx,
      { space: fact.space, doc: fact.doc, formats: ["pdf"] },
      { then: rendered.with({ brief }) },
    );
  },
);

export const rendered = mutation(
  { under: workspace, args: { brief: t.key(briefs), result: t.result(docs.ready) } },
  async (ctx, { brief, result }) => {
    if (!result.ok || result.value.state === "failed") return await ctx.patch(briefs(brief), { state: "failed" });
    await ctx.patch(briefs(brief), { state: "ready", report: result.value.report });
  },
);
```

A render that never answers expires the ready task. A reaction on the
report table sees every report settle as well:
`mutation({ on: docs.tables.reports.changes, roles: [editor] }, …)`.

## Release a report

A report stays at the library's label. Releasing it copies its files to a
lower audience through a declared [release](https://docs.bijection.com/access/disclosure.md). Give the
library a `publish` option:

```ts theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
import { label, release, role } from "@bijectionhq/bijection";

export const member = role({});
export const toMembers = release({ from: workspace, to: label.public, message: "Released reports are read by members" });

documents({
  // ...
  publish: {
    release: toMembers,
    label: label.public,
    audience: [member],
    gate: async (ctx, report, releaser) => {
      // ctx.refuse(...) stops the release, for example when no review
      // passed on exactly report.digest.
    },
    onRelease: async (ctx, { published, report, releaser }) => {},
  },
});
```

`reports.release({ space, report })`, or `docs.helpers.release(ctx, { space,
report })` in your own function, runs `gate` under the documents' label,
opens the report's files, stores the copies through the release
(`ctx.store(input, { label, release })`), writes the publication fact at the
audience's label and runs `onRelease`, all in one transaction. A function
that calls the helper declares the release in its `releases`. Releasing
again answers the first release and runs nothing. Audience roles read the
copies through `published.list`.

## Lifetime

Reports are deleted after `renderer.lifetime` (30 days by default).
Uploads no render claims are dropped after a day, and a file no fact keeps
is retired by the host.

The [document deliverables example](https://github.com/bijectionhq/bijection/tree/main/examples/document-deliverables)
shows a report flow with review before release.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.