CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-notion-types

TypeScript types for core Notion data structures.

Pending

Quality

Pending

Does it follow best practices?

Impact

Pending

No eval scenarios have been run

Overview
Eval results
Files

collection-views.mddocs/

Collection Views

Type definitions for all Notion database view types including table, gallery, list, board, and calendar views with their configuration options and display settings.

Capabilities

Base Collection View

All collection views inherit from the BaseCollectionView interface.

/**
 * Base properties for all collection views
 */
interface BaseCollectionView {
  /** View identifier */
  id: ID;
  /** View type */
  type: CollectionViewType;
  /** View name */
  name: string;
  /** View-specific formatting */
  format: any;
  /** View version */
  version: number;
  /** Whether view is active */
  alive: boolean;
  /** Parent collection ID */
  parent_id: ID;
  /** Parent table type */
  parent_table: string;
  /** Legacy query format */
  query?: any;
  /** Current query format */
  query2: {
    /** Filter criteria */
    filter?: any;
    /** Aggregation functions */
    aggregations?: object[];
    /** Grouping property */
    group_by: string;
  };
}

View Types

/**
 * Types of collection views supported by Notion
 */
type CollectionViewType =
  | 'table'      // Table view
  | 'gallery'    // Gallery/card view
  | 'list'       // List view
  | 'board'      // Kanban board view
  | 'calendar'   // Calendar view
  | 'reducer';   // Aggregated view

/**
 * Union type of all collection view interfaces
 */
type CollectionView =
  | TableCollectionView
  | GalleryCollectionView
  | ListCollectionView
  | BoardCollectionView
  | CalendarCollectionView
  | ReducerCollectionView;

Cover Configuration

/**
 * Cover image source types
 */
type CollectionCardCoverType =
  | 'page_cover'     // Use page cover image
  | 'page_content'   // Use page content as cover
  | 'property'       // Use property value as cover
  | 'none'           // No cover
  | 'file';          // Use file as cover

/**
 * Cover image sizes
 */
type CollectionCardCoverSize = 'small' | 'medium' | 'large';

/**
 * Cover image aspect ratio handling
 */
type CollectionCardCoverAspect = 'cover' | 'contain';

/**
 * Card cover configuration
 */
interface CollectionCardCover {
  /** Cover source type */
  type: CollectionCardCoverType;
  /** Property to use as cover (if type is 'property') */
  property?: string;
}

Table View

/**
 * Table view configuration
 */
interface TableCollectionView extends BaseCollectionView {
  type: 'table';
  /** Table-specific formatting */
  format: {
    /** Whether to wrap table content */
    table_wrap: boolean;
    /** Column configuration */
    table_properties: Array<{
      property: string;
      visible: boolean;
      width: number;
    }>;
  };
  /** Page sort order */
  page_sort: string[];
}

Gallery View

/**
 * Gallery view configuration
 */
interface GalleryCollectionView extends BaseCollectionView {
  type: 'gallery';
  /** Gallery-specific formatting */
  format: {
    /** Card cover settings */
    gallery_cover: CollectionCardCover;
    /** Cover size */
    gallery_cover_size: CollectionCardCoverSize;
    /** Cover aspect ratio */
    gallery_cover_aspect: CollectionCardCoverAspect;
    /** Property visibility */
    gallery_properties: Array<{
      property: string;
      visible: boolean;
    }>;
  };
}

List View

/**
 * List view configuration
 */
interface ListCollectionView extends BaseCollectionView {
  type: 'list';
  /** List-specific formatting */
  format: {
    /** Property visibility */
    list_properties: Array<{
      property: string;
      visible: boolean;
    }>;
  };
}

Board View

/**
 * Board/Kanban view configuration
 */
interface BoardCollectionView extends BaseCollectionView {
  type: 'board';
  /** Board-specific formatting */
  format: {
    /** Card cover settings */
    board_cover: CollectionCardCover;
    /** Cover size */
    board_cover_size: CollectionCardCoverSize;
    /** Cover aspect ratio */
    board_cover_aspect: CollectionCardCoverAspect;
    /** Property visibility */
    board_properties: Array<{
      property: string;
      visible: boolean;
    }>;
    /** Board grouping configuration */
    board_groups2: Array<{
      property: string;
      hidden: boolean;
      value: {
        type: PropertyType;
        value: string;
      };
    }>;
    /** Board column configuration */
    board_columns: Array<{
      property: string;
      hidden: boolean;
      value: {
        type: PropertyType;
        value: string;
      };
    }>;
  };
}

Calendar View

/**
 * Calendar view configuration
 */
interface CalendarCollectionView extends BaseCollectionView {
  type: 'calendar';
  // Additional properties TODO in source
}

Reducer View

/**
 * Aggregated view configuration
 */
interface ReducerCollectionView extends BaseCollectionView {
  type: 'reducer';
  /** Aggregation results */
  reducerResults: {
    collection_group_results: object;
  };
  /** Size hint for rendering */
  sizeHint: number;
}

Usage Examples:

import { 
  CollectionView,
  TableCollectionView,
  GalleryCollectionView,
  BoardCollectionView,
  CollectionViewType,
  CollectionCardCover 
} from "notion-types";

// Create a table view
const tableView: TableCollectionView = {
  id: "view-123",
  type: "table",
  name: "All Users",
  format: {
    table_wrap: true,
    table_properties: [
      { property: "title", visible: true, width: 200 },
      { property: "email", visible: true, width: 250 },
      { property: "status", visible: true, width: 120 },
      { property: "age", visible: false, width: 80 }
    ]
  },
  version: 1,
  alive: true,
  parent_id: "collection-456",
  parent_table: "collection",
  page_sort: [],
  query2: {
    group_by: "status"
  }
};

// Create a gallery view
const galleryView: GalleryCollectionView = {
  id: "view-789",
  type: "gallery",
  name: "User Cards",
  format: {
    gallery_cover: {
      type: "property",
      property: "profile_image"
    },
    gallery_cover_size: "medium",
    gallery_cover_aspect: "cover",
    gallery_properties: [
      { property: "title", visible: true },
      { property: "email", visible: true },
      { property: "status", visible: true }
    ]
  },
  version: 1,
  alive: true,
  parent_id: "collection-456",
  parent_table: "collection",
  query2: {
    group_by: "status"
  }
};

// Create a board view
const boardView: BoardCollectionView = {
  id: "view-101",
  type: "board",
  name: "Status Board",
  format: {
    board_cover: {
      type: "page_cover"
    },
    board_cover_size: "small",
    board_cover_aspect: "cover",
    board_properties: [
      { property: "title", visible: true },
      { property: "email", visible: true }
    ],
    board_groups2: [
      {
        property: "status",
        hidden: false,
        value: { type: "select", value: "Active" }
      },
      {
        property: "status",
        hidden: false,
        value: { type: "select", value: "Pending" }
      }
    ],
    board_columns: [
      {
        property: "status",
        hidden: false,
        value: { type: "select", value: "Active" }
      }
    ]
  },
  version: 1,
  alive: true,
  parent_id: "collection-456",
  parent_table: "collection",
  query2: {
    group_by: "status"
  }
};

// Type guard functions
function isTableView(view: CollectionView): view is TableCollectionView {
  return view.type === 'table';
}

function isGalleryView(view: CollectionView): view is GalleryCollectionView {
  return view.type === 'gallery';
}

// Process different view types
function configureView(view: CollectionView) {
  switch (view.type) {
    case 'table':
      const tableView = view as TableCollectionView;
      console.log('Table columns:', tableView.format.table_properties.length);
      break;
    case 'gallery':
      const galleryView = view as GalleryCollectionView;
      console.log('Gallery cover:', galleryView.format.gallery_cover.type);
      break;
    case 'board':
      const boardView = view as BoardCollectionView;
      console.log('Board groups:', boardView.format.board_groups2.length);
      break;
  }
}

Install with Tessl CLI

npx tessl i tessl/npm-notion-types

docs

api.md

blocks.md

collection-views.md

collections.md

formatting.md

formulas.md

index.md

users.md

tile.json