# Deploy from TypeScript (/docs/cloud/deploy-typescript)

<Component />

## 1. Declare what cloud publishes [#1-declare-what-cloud-publishes]

Create a deployment entrypoint that exports the result of `publishToCloud` as `cloud`:

<CodeBlock>
```typescript
// analytics/cloud.ts
import { publishToCloud } from '@hypequery/datasets';
import { orders } from './orders';

export const cloud = publishToCloud({
  datasets: { orders },
  access: { roles: ['analyst'], scopes: [] },
});
```
</CodeBlock>

- `datasets` lists the datasets cloud exposes. Datasets they relate to are included as supporting datasets.
- `access` is required: the roles and scopes callers need for every published dataset.
- `datasetAccess` optionally sets a different policy for individual datasets, keyed by published name.
- `endpoints` optionally gives a published dataset's exact endpoint policy, keyed by name. It replaces the policy `access` derives, which is authenticated, injects the tenant from `tenantKey`, and caps rows at `limits.maxResultSize` or 1,000. Use it for what that can't say, such as a cache TTL or no row cap. Code exported from hypequery cloud uses it to rebuild a model exactly.
- `supporting` optionally lists datasets to publish without an endpoint, beyond those reached through a relationship. They can't be queried directly.

`publishToCloud` makes no network request. It only builds the contract that the CLI uploads.

Segments, window and shift measures, `approxCountDistinct`, and a `minute` or `hour` default grain are published as deployment contract 3. A deployment that uses none of them stays on contract 2, so its identity does not change. Every published dataset with a `timeKey` can be grouped by any grain, `minute` through `year`. A deployment contract cannot carry a `timeGrains` restriction, so a dataset that sets one must list all seven grains or stay local.

## 2. Log in [#2-log-in]

<CodeBlock>
```bash
npx hypequery login
```
</CodeBlock>

This authorizes the machine with hypequery cloud and saves your default project and environment.

## 3. Deploy [#3-deploy]

<CodeBlock>
```bash
npx hypequery deploy analytics/cloud.ts
```
</CodeBlock>

The CLI builds a bundle, prepares a release for your target, and submits it. Once cloud accepts the release, it prints
where the datasets are served:

<CodeBlock>
```text
Hosted endpoints
  REST  https://<environment-slug>.hypequery.app
    orders  POST https://<environment-slug>.hypequery.app/api/analytics/datasets/orders/query
  MCP   https://<environment-slug>.hypequery.app/mcp
```
</CodeBlock>

Add `--mcp-config` to also print a ready-to-use [MCP client configuration](/docs/cloud/mcp).

## Useful options [#useful-options]

| Option | Description |
| --- | --- |
| `--project`, `--environment` | Deploy to a different target than the one saved by `hypequery login` |
| `--no-source` | Leave project source files out of the bundle |
| `--mcp-config` | Print MCP client configuration for the hosted endpoint |
| `--replace-restored` | Replace a live release that was restored from history |
| `--take-ownership` | Replace a live model built in hypequery Cloud. The project is then managed in code. Without it, the CLI asks in a terminal and refuses in CI |