diff --git a/js-pkg/sdk/src/main.ts b/js-pkg/sdk/src/main.ts index 945001fb..8a112cd6 100644 --- a/js-pkg/sdk/src/main.ts +++ b/js-pkg/sdk/src/main.ts @@ -135,6 +135,18 @@ export class DocumentManager { const clientToken = await this.getClientToken(docId, authDocRequest) return new DocConnection(clientToken) } + + /** + * Creates a new document with initial content. + * + * @param update A Yjs update byte string representing the initial content. + * @returns A {@link DocCreationResult} object containing the ID of the created document. + */ + public async createDocWithContent(update: Uint8Array): Promise { + const result = await this.createDoc() + await this.updateDoc(result.docId, update) + return result + } } /** @@ -187,3 +199,19 @@ export async function createDoc( const manager = new DocumentManager(connectionString) return await manager.createDoc(docId) } + +/** + * A convenience wrapper around {@link DocumentManager.createDocWithContent} for creating a new document + * with initial content. + * + * @param connectionString A connection string (starting with `ys://` or `yss://`) referring to a y-sweet server. + * @param update A Yjs update byte string representing the initial content. + * @returns A {@link DocCreationResult} object containing the ID of the created document. + */ +export async function createDocWithContent( + connectionString: string, + update: Uint8Array, +): Promise { + const manager = new DocumentManager(connectionString) + return await manager.createDocWithContent(update) +}