> ## 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.

# Publish a table as a dataset

A sync keeps a dataset continuously equal to one table of your app. The table's
facts leave only through its feed. A writer (the cell's Lake Writer, or your own
engine) reads the feed, writes files and stages snapshots, and the Datasets
installation commits each one.

## Publish a table

Declare the sync with `tableSync` from `@bijectionhq/library-transfer`, naming the table
and the dataset it is kept in. The `transfer({...})` subtree is placed in your
tree beside the Datasets installation:

```ts bijection/app.ts theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
import { app, label, role, t, table } from "@bijectionhq/bijection";
import { datasets } from "@bijectionhq/datasets-app";
import { tableSync, transfer } from "@bijectionhq/library-transfer";
import { candidatePassed } from "./gates"; // the admit query (see Datasets)

export const orders = table({ customer: t.string, total: t.decimal }, {});
export const operator = role({});
export const exporter = role({});
export const lake = datasets({ admit: candidatePassed });

export const transfers = transfer({
  label: label.public,
  operators: [operator],
  exporters: [exporter],
  datasets: lake,
  syncs: {
    orders: tableSync({
      table: orders,
      shape: "mirror",
      into: { dataset: "orders", catalog: "lake" },
      freshness: "1m",
    }),
  },
});

export default app({ orders, operator, exporter, candidatePassed, lake, transfers });
```

Then an operator attaches it once: `transfers.lake.attach({ sync: "orders" })`
creates the dataset in `into.catalog` if absent and declares the sync to the
Datasets installation. Register the writer as the feed's consumer with
`transfers.feeds.register({ sync, consumer, principal, authorization: "principal" })`, where `principal`
is the writer's complete `service:` principal ID. Grant that principal the
`exporter` role.

An erasable table needs `erasure: "release"` on its `tableSync` before its facts
may leave to a destination outside Bijection. A group of up to
sixteen tables (`tableSync({ tables: { a, b }, shape, into })`) is kept table by
table, each in its own dataset, committed together at one version.

### Mirror or change log

* `shape: "mirror"` keeps the table's current state: each page collapses to
  every fact's last change.
* `shape: "log"` keeps every change, insert-only.

Schema changes and erasures travel in band. A change of shape starts a new
generation of the sync.

### How a table becomes a dataset

The writer loops:

1. `transfers.feeds.page({ sync, consumer, ack })` reads the next page.
2. `transfers.lake.next({ sync, consumer })` answers what to stage: the
   generation, ordinal, parent snapshot, target ref and the exact snapshot
   summary to write.
3. The writer writes the files and adds the snapshot with that summary, moving
   no ref.
4. `transfers.lake.stage` asks the Datasets installation to commit it (a task of
   its `staging` target). The writer reads `transfers.lake.committed` and
   acknowledges the page only on `published`; it stages again on `restage` or
   `failed`, and starts a new generation (`ack: 0`) on `reset`.

Each commit asserts the ref is at the previous ordinal's snapshot and is
confirmed only from the catalog's metadata, so a resent commit is never applied
twice and the feed never skips a page. Ingest, compaction, erasure rewrites and
snapshot expiry are ordinals of one writer sequence per generation and never
race. A new generation (a restore, a reset, a moved table) backfills into a seed
ref and switches `main` only when the backfill is complete, so readers never see
a partial table.

A confirmed range is a snapshot on `main`. The head is tagged as a version at
the sync's publication cadence (hourly by default) or when you submit to
`lake.pinning` with `{ dataset, ref: null }`; a default read leases the head
directly.

### Check that it has caught up

`freshness` is `"1m"` (default), `"15m"` or `"1h"`; the writer pages at half of
it. `lake.syncs.get({ dataset, ref: null })` answers the generation, confirmed
ordinal, head, cursor, `lag` (the age of the oldest change no ordinal carries)
and `stale` (`lag` above the bound). `transfers.feeds.status` shows the
consumer's side. The feed keeps seven days of history by default; a consumer
idle longer starts again from a new snapshot.

### Query it from your engine

Open a [read lease](https://docs.bijection.com/datasets/exact-reads.md) and pass it to your engine, or publish
a [view](https://docs.bijection.com/datasets/consumer-views.md).

### Adopt a snapshot a partner wrote

A partner or engine that lands a whole snapshot in the managed catalog has it
adopted as the next version with the transfer library's `datasetLoad`, through
the dataset's `admit` gate. Use it for datasets that are not synced.


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