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

# Google Sheets Drive-version reads

> Observe a bounded Google Sheets range and tab metadata with a Drive file version check.

The app reads the Drive file version, fetches one grid range and its tab
metadata, and then reads the Drive version again. It publishes the draft
only when Drive returns the same file version on both reads. If the
version moves, the last committed position stays in place and the next
pass starts with a new version check. Workbook writers use Google Sheets
as usual.

Google documents `headRevisionId` for binary Drive files. For Google
spreadsheets the check uses the file resource's monotonically increasing
`version`. This is a check around a live Sheets read. Historical revision
downloads and cross-API snapshot isolation are outside the contract.
Formulas land as entered text rather than recalculated output.

## Mount and bind

`sheets({ data, drive, provider })` returns the app to place at a path of
your tree. Bind the Drive version check and the grid read for the same
spreadsheet.

```ts app.ts theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
import { app, label, secret } from "@bijectionhq/bijection";
import sheets, { googleDriveVersion, googleSpreadsheet } from "@bijectionhq/app-sheets";

const samples = label();
const driveToken = secret();
const sheetsToken = secret();
const spreadsheetId = "REPLACE_WITH_SPREADSHEET_ID";
const drive = googleDriveVersion(spreadsheetId, { kind: "bearer", secret: driveToken }, samples);
const workbook = googleSpreadsheet(spreadsheetId, { kind: "bearer", secret: sheetsToken }, samples);

export default app({ samples, driveToken, sheetsToken, drive, workbook, sheets: sheets({ data: samples, drive, provider: workbook }) });
```

```sh theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
bijection secret set driveToken
bijection secret set sheetsToken
bijection mutate sheets.source.initialize '{"selection": {"spreadsheetId": "REPLACE_WITH_SPREADSHEET_ID", "sheetId": 17, "title": "Samples", "row": 0, "column": 0, "rows": 32, "columns": 8}}'
```

`sheets.operator` is granted from code: `ctx.grant(sheets.operator, { to, under })` in one of your
mutations ([Grants](https://docs.bijection.com/access/grants.md)).

Use scoped read-only credentials: `drive.metadata.readonly` for the Drive
file check and `spreadsheets.readonly` for the grid read. Both receivers must
select the same spreadsheet and live under the mount's `data` label. The
mount's `operator` role clears it and is the only role its functions allow.

The range uses zero-based coordinates and admits up to 64 rows, 16
columns, 512 cells total, and 36 KiB per response. Blank cells are null.
Rows are keyed by workbook, tab, Drive version, row, starting column,
and width. The app publishes the rows, tab metadata, and the Drive
version position together and retains earlier versions. A tab or row
omission does not delete prior observations. To change the installed
range, call `sheets.source.advance` with the new selection and the source
configuration revision from `source.health`.

[Drive file versions](https://developers.google.com/workspace/drive/api/reference/rest/v3/files)
[Sheets spreadsheet reads](https://developers.google.com/workspace/sheets/api/reference/rest/v4/spreadsheets/get)


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