Implementation:AFK surf Open agent Create Starter Doc Collection
| Knowledge Sources | |
|---|---|
| Domains | Editor, CRDT_Sync, BlockSuite |
| Last Updated | 2026-10-25 00:00 GMT |
Overview
Concrete factory that constructs a BlockSuite TestWorkspace doc collection with registered AffineSchemas, pluggable doc/blob/awareness sources, and attached store extensions.
Description
createStarterDocCollection is the canonical factory in the starter playground for assembling a DocCollection. It builds a Schema and registers the AffineSchemas, chooses an id generator (nanoid for production, auto-increment for E2E), wires optional BroadcastChannelDocSource doc sources for local collaboration, MemoryBlobSource (with optional IndexedDBBlobSource/MockServerBlobSource shadows) for blobs, and BroadcastChannelAwarenessSource for presence. Store extensions from the manager are attached via collection.storeExtensions = manager.get('store') before collection.start() is called. A Transformer is also constructed for import/export and debugging and exposed on window.job.
Usage
Call this function after registering effects and obtaining the store extension manager, and before initializing document content. It is used by the starter playground main() and by any custom integration that wants the same wiring as the playground.
Code Reference
Source Location
- Repository: Open-Agent
- File: blocksuite/playground/apps/starter/utils/collection.ts (L26-79)
Signature
function createStarterDocCollection(
storeExtensionManager: StoreExtensionManager
): TestWorkspace;
Import
import { createStarterDocCollection } from './utils/collection.js';
import { Schema, AffineSchemas, nanoid, Transformer } from '@blocksuite/affine/store';
import { TestWorkspace, createAutoIncrementIdGenerator, DocCollectionOptions } from '@blocksuite/affine/store/test';
import {
BroadcastChannelAwarenessSource,
BroadcastChannelDocSource,
IndexedDBBlobSource,
MemoryBlobSource,
} from '@blocksuite/affine/sync';
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| storeExtensionManager | StoreExtensionManager | Yes | Provides store-scoped extensions attached to the collection |
| URL params (room, blobSource) | string | Drive doc id, blob source selection ('mock','idb') |
Outputs
| Name | Type | Description |
|---|---|---|
| collection | TestWorkspace | A started collection with storeExtensions set; debug globals window.collection/window.job/window.Y populated |
Usage Examples
Standard Collection Creation
const storeManager = getTestStoreManager();
const collection = createStarterDocCollection(storeManager);
// collection is now started; attach a doc preset next:
await initStarterDocCollection(collection);
With IndexedDB Blob Shadow
// Visit the playground with ?blobSource=idb,mock to enable IndexedDB + mock server shadows
// URL: /?room=dev&blobSource=idb,mock
const collection = createStarterDocCollection(storeManager);
// MemoryBlobSource is the main source; IndexedDBBlobSource + MockServerBlobSource are shadows