# サンプル

> 機能別に Collaboration SDK のサンプルを実行し、ガイドとサーバー・Web の入口を確認します。

- Human documentation: [https://docs.univer.ai/ja-JP/server/collaboration/examples](https://docs.univer.ai/ja-JP/server/collaboration/examples)

- Agent Markdown: [https://docs.univer.ai/ja-JP/server/collaboration/examples.md](https://docs.univer.ai/ja-JP/server/collaboration/examples.md)

- Requested language: `ja-JP`

- Content language: `ja-JP`

- Documentation version: `1.1.0`

- Source: [collaboration/examples.ja-JP.mdx](https://github.com/dream-num/documentation/blob/dev/content/server/collaboration/examples.ja-JP.mdx)

---

すべてのサンプルは [univer-collaboration-examples](https://github.com/dream-num/univer-collaboration-examples) にあります。同じ最小構成 `web/main.ts + server/main.ts` で独立して動作します。まずクイックスタートを完了し、統合する内容に応じて次の例を選びます。

| サンプル                             | 主な概念          | コマンド                            |
| -------------------------------- | ------------- | ------------------------------- |
| [クイックスタート](#quick-start)         | 基本の共同編集経路     | `pnpm example:quick-start`      |
| [データベースアダプター](#database-adapter) | データベースアダプター   | `pnpm example:database-adapter` |
| [権限](#permissions)               | 本人確認と認可       | `pnpm example:permissions`      |
| [履歴](#history)                   | 派生バージョン履歴     | `pnpm example:history`          |
| [コメント](#comments)                | 独立したコメント      | `pnpm example:comments`         |
| [Worktree](#worktree)            | 隔離編集とマージ      | `pnpm example:worktree`         |
| [ファイル変換](#exchange)              | Office ファイル変換 | `pnpm example:exchange`         |
| [複数ノードへのデプロイ](#multi-node)       | 水平スケーリング      | `pnpm example:multi-node`       |

## クイックスタート

Collaboration Client、Transport、Endpoint、Service、Memory Adapter を組み合わせます。2 つのブラウザーで同じ Sheet の HTTP 読み込み、WebSocket Session、Room、ACK、配信を確認します。

```bash
pnpm example:quick-start
```

`http://127.0.0.1:3010/?unit=quick-start-sheet` を開きます。

* [サンプルガイド](https://github.com/dream-num/univer-collaboration-examples/blob/main/examples/quick-start/README.md)
* [サーバー入口](https://github.com/dream-num/univer-collaboration-examples/blob/main/examples/quick-start/server/main.ts)
* [Web 入口](https://github.com/dream-num/univer-collaboration-examples/blob/main/examples/quick-start/web/main.ts)
* [当サイトの手順ガイド](https://docs.univer.ai/ja-JP/server/collaboration/quick-start.md)

## データベースアダプター

組み込みの SQLite Adapter の使い方と、カスタム Database Adapter の実装を示します。

```bash
pnpm example:database-adapter
```

`http://127.0.0.1:3010/?unit=persistent-sheet` を開きます。

* [サンプルガイド](https://github.com/dream-num/univer-collaboration-examples/blob/main/examples/database-adapter/README.md)
* [サーバー入口](https://github.com/dream-num/univer-collaboration-examples/blob/main/examples/database-adapter/server/main.ts)
* [Web 入口](https://github.com/dream-num/univer-collaboration-examples/blob/main/examples/database-adapter/web/main.ts)

## 権限

Cookie から信頼できる ID を確立し、Unit の HTTP 読み取り、リアルタイム JOIN、変更送信を個別に保護します。ページでは学習用の **Alice · Editor** と読み取り専用 **Bob · Viewer** を切り替えます。

```bash
pnpm example:permissions
```

`http://127.0.0.1:3010` を開きます。

* [サンプルガイド](https://github.com/dream-num/univer-collaboration-examples/blob/main/examples/permissions/README.md)
* [サーバー入口](https://github.com/dream-num/univer-collaboration-examples/blob/main/examples/permissions/server/main.ts)
* [Web 入口](https://github.com/dream-num/univer-collaboration-examples/blob/main/examples/permissions/web/main.ts)
* [本人確認と認可のガイド](https://docs.univer.ai/ja-JP/server/collaboration/identity-and-authorization.md)

## 履歴

基本モジュールの外に History Service、独立 Adapter、History Endpoint、ブラウザーの履歴入口を追加します。Unit 作成と変更コミットの Events で再構築可能な派生索引を作ります。

```bash
pnpm example:history
```

`http://127.0.0.1:3010/?unit=history-sheet` を開き、Sheet を編集してページ上部の `History` を選びます。

* [サンプルガイド](https://github.com/dream-num/univer-collaboration-examples/blob/main/examples/history/README.md)
* [サーバー入口](https://github.com/dream-num/univer-collaboration-examples/blob/main/examples/history/server/main.ts)
* [Web 入口](https://github.com/dream-num/univer-collaboration-examples/blob/main/examples/history/web/main.ts)

## コメント

Thread Comment Service、独立 Adapter、Comment Endpoint、フロントエンドのコメント入口を追加します。Comment Endpoint は主 Endpoint の Session と Unit Room を再利用します。

```bash
pnpm example:comments
```

`http://127.0.0.1:3010/?unit=comments-sheet` を開き、セルを選んでコメント機能を使います。

* [サンプルガイド](https://github.com/dream-num/univer-collaboration-examples/blob/main/examples/comments/README.md)
* [サーバー入口](https://github.com/dream-num/univer-collaboration-examples/blob/main/examples/comments/server/main.ts)
* [Web 入口](https://github.com/dream-num/univer-collaboration-examples/blob/main/examples/comments/web/main.ts)

## Worktree

隔離した下書き、Ready、Reopen、Unit ごとの Merge の全ライフサイクルを示します。トランクと下書きを切り替え、マージ前の AI Agent の変更の隔離を確認します。

```bash
pnpm example:worktree
```

`http://127.0.0.1:3010/?unit=worktree-sheet&worktree=demo-worktree` を開きます。

* [サンプルガイド](https://github.com/dream-num/univer-collaboration-examples/blob/main/examples/worktree/README.md)
* [サーバー入口](https://github.com/dream-num/univer-collaboration-examples/blob/main/examples/worktree/server/main.ts)
* [Web 入口](https://github.com/dream-num/univer-collaboration-examples/blob/main/examples/worktree/web/main.ts)
* [CLI と人によるレビュー](https://docs.univer.ai/ja-JP/ai/worktree.md)

## ファイル変換

`@univerjs-pro/exchange-node` と Collaboration Service を組み合わせ、サーバーでの Sheet 入出力、タスクのポーリング、スナップショット取り込み、確定リビジョン出力を行います。

```bash
pnpm example:exchange
```

`http://127.0.0.1:3010/?unit=exchange-sheet` を開きます。**File → Open (File)** で取り込み、**File → Save As** で出力します。

* [サンプルガイド](https://github.com/dream-num/univer-collaboration-examples/blob/main/examples/exchange/README.md)
* [サーバー入口](https://github.com/dream-num/univer-collaboration-examples/blob/main/examples/exchange/server/main.ts)
* [ファイル変換フロー](https://github.com/dream-num/univer-collaboration-examples/blob/main/examples/exchange/server/exchange.ts)
* [Web 入口](https://github.com/dream-num/univer-collaboration-examples/blob/main/examples/exchange/web/main.ts)

## 複数ノードへのデプロイ

Nginx の背後で 2 つのコラボレーションノードを実行します。Redis がノード間でリアルタイム更新を中継し、Session Ticket を共有するため、どのノードでもどのリクエストも処理できます。Docker Compose が必要です。

```bash
pnpm example:multi-node
```

`http://127.0.0.1:3010/` を開き、**New Sheet** をクリックしてファイルを作成します。完全な URL を別のタブにコピーし、同じ文書の共同編集を確認します。さらにファイルをいくつか作成し、各ノードへの割り当てを確認します。

* [サンプルガイド](https://github.com/dream-num/univer-collaboration-examples/blob/main/examples/multi-node/README.md)

> [!NOTE: サンプルは本番アプリケーションではありません]
> 固定ユーザー、学習用認可、Memory Adapter、ローカルの秘密情報、メモリ内のファイル・タスク保存は教材用です。本人確認、認可、永続化、秘密情報、ファイル、デプロイ、製品操作はアプリケーションが担当します。
