@datalayer/core
Version:
[](https://datalayer.io)
281 lines (280 loc) • 7.06 kB
TypeScript
import type { DatalayerClient } from '../index';
import { NotebookDTO, type NotebookJSON } from './NotebookDTO';
import { NotebookData } from './NotebookDTO';
import { LexicalDTO, type LexicalJSON } from './LexicalDTO';
/**
* Represents a workspace or project space in Datalayer
* @interface SpaceData
*/
export interface SpaceData {
uid: string;
name_t: string;
handle_s: string;
variant_s: string;
description_t: string;
tags_ss?: string[];
members?: any[];
items?: any[];
}
/**
* Stable public interface for Space data.
* This is the contract that SDK consumers can rely on.
* The raw API may change, but this interface remains stable.
*/
export interface SpaceJSON {
/** ulid for the space */
uid: string;
/** Name of the space */
name: string;
/** Handle for the space */
handle: string;
/** Variant of the space */
variant: string;
/** Description of the space */
description: string;
/** Items contained in the space (as JSON) */
items: Array<NotebookJSON | LexicalJSON>;
}
/**
* Space domain model that wraps API responses with convenient methods.
* Provides workspace management with data refresh and content creation operations.
*
* @example
* ```typescript
* const space = spaces[0];
* const items = await space.getItems();
* const notebook = await space.createNotebook({ name: 'Analysis' });
* ```
*/
export declare class SpaceDTO {
protected _data: SpaceData;
private _sdk;
private _items;
private _deleted;
/**
* Create a Space instance.
*
* @param data - Space data from API
* @param sdk - SDK instance
*/
constructor(data: SpaceData, sdk: DatalayerClient);
/**
* Check if this space has been deleted and throw error if so.
* @throws Error if deleted
*/
private _checkDeleted;
/**
* Refresh space data from the API by fetching user's spaces.
*/
refresh(): Promise<void>;
/** Unique identifier for the space. */
get uid(): string;
/** URL-friendly handle for the space. */
get handle(): string;
/** Space variant type. */
get variant(): string;
/**
* The name of the space.
*/
get name(): string;
/**
* The description of the space.
*/
get description(): string;
/**
* Helper method to create items in this space.
*
* @param itemType - Type of item to create
* @param data - Creation configuration
* @returns Created model instance
* @internal
*/
private _createItem;
/**
* Get all items in this space as model instances.
*
* @returns Array of Notebook and Lexical model instances
*/
getItems(): Promise<(NotebookDTO | LexicalDTO)[]>;
/**
* Create a new notebook in this space.
*
* @param data - Notebook creation configuration
* @returns Created Notebook instance
*/
createNotebook(data: {
name: string;
description: string;
file?: File | Blob;
}): Promise<NotebookDTO>;
/**
* Create a new lexical document in this space.
*
* @param data - Lexical creation configuration
* @returns Created Lexical instance
*/
createLexical(data: {
name: string;
description: string;
file?: File | Blob;
}): Promise<LexicalDTO>;
/**
* Get raw space data object.
* Returns cached data without refreshing.
*
* @returns Raw space data object
*/
/**
* Get space data in camelCase format.
* Returns only the core fields that consumers need.
* This provides a stable interface regardless of API changes.
*
* @returns Core space data with camelCase properties
*/
toJSON(): SpaceJSON;
/**
* Get the raw space data exactly as received from the API.
* This preserves the original snake_case naming from the API response.
*
* @returns Raw space data from API
*/
rawData(): SpaceData;
/** String representation of the space. */
toString(): string;
}
/**
* Request payload for creating a new space
* @interface CreateSpaceRequest
*/
export interface CreateSpaceRequest {
name: string;
description: string;
variant: string;
spaceHandle: string;
organizationId: string;
seedSpaceId: string;
public: boolean;
}
/**
* Response from getting a collaboration session ID
* @interface CollaborationSessionResponse
*/
export interface CollaborationSessionResponse {
success: boolean;
sessionId?: string;
error?: string;
}
/**
* Response from creating a space
* @interface CreateSpaceResponse
*/
export interface CreateSpaceResponse {
success: boolean;
message: string;
space?: SpaceData;
}
/**
* Request payload for creating a new notebook (multipart/form-data)
* @interface CreateNotebookRequest
*/
export interface CreateNotebookRequest {
spaceId: string;
notebookType: string;
name: string;
description: string;
file?: File | Blob;
}
/**
* Response from creating a notebook
* @interface CreateNotebookResponse
*/
export interface CreateNotebookResponse {
success: boolean;
message: string;
notebook?: NotebookData;
}
/**
* Response from getting a notebook
* @interface GetNotebookResponse
*/
export interface GetNotebookResponse {
success: boolean;
message: string;
notebook?: NotebookData;
}
/**
* Request payload for creating a notebook
* @interface CreateNotebookRequest
*/
export interface CreateNotebookRequest {
spaceId: string;
notebookType: string;
name: string;
description: string;
file?: File | Blob;
}
/**
* Request payload for updating a notebook
* @interface UpdateNotebookRequest
*/
export interface UpdateNotebookRequest {
name?: string;
description?: string;
}
/**
* Response from updating a notebook
* @interface UpdateNotebookResponse
*/
export interface UpdateNotebookResponse {
success: boolean;
message: string;
notebook?: NotebookData;
}
/**
* Represents an item within a space
* @interface SpaceItem
*/
export interface SpaceItem {
id: string;
type_s: 'notebook' | 'lexical';
space_id: string;
item_id: string;
name: string;
created_at: string;
updated_at?: string;
}
/**
* Response from getting space items
* @interface GetSpaceItemsResponse
*/
export interface GetSpaceItemsResponse {
success: boolean;
message: string;
items: SpaceItem[];
}
/**
* Response from deleting a space item
* @interface DeleteSpaceItemResponse
*/
export interface DeleteSpaceItemResponse {
success: boolean;
message: string;
}
/**
* Response from getting a single space item
* @interface GetSpaceItemResponse
*/
export interface GetSpaceItemResponse {
success: boolean;
message: string;
item?: any;
}
/**
* Response from getting spaces for a user
* @interface SpacesForUserResponse
*/
export interface SpacesForUserResponse {
success: boolean;
message: string;
spaces: SpaceData[];
}