@datalayer/core
Version:
[](https://datalayer.io)
33 lines (32 loc) • 1.2 kB
JavaScript
/*
* Copyright (c) 2023-2025 Datalayer, Inc.
* Distributed under the terms of the Modified BSD License.
*/
import { NotebookDTO } from '../../models/NotebookDTO';
import { LexicalDTO } from '../../models/LexicalDTO';
import { ItemTypes } from '../constants';
/**
* Convert raw space items from API response to model instances.
* This utility function is shared between Space.getItems() and SpacerMixin.getSpaceItems()
* to avoid code duplication.
*
* @param response - Raw API response containing space items
* @param sdk - SDK instance to pass to model constructors
* @returns Array of Notebook and Lexical model instances
*/
export function convertSpaceItemsToModels(items, sdk) {
const modelItems = [];
for (const item of items) {
// Check various possible type fields
const itemType = item.type_s;
// Only include notebooks and lexicals
if (itemType === ItemTypes.NOTEBOOK) {
modelItems.push(new NotebookDTO(item, sdk));
}
else if (itemType === ItemTypes.LEXICAL) {
modelItems.push(new LexicalDTO(item, sdk));
}
// Skip everything else (exercises, cells, etc.)
}
return modelItems;
}