or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

cli.mdcomposables.mdextensions.mdindex.mdutilities.md
tile.json

composables.mddocs/

Vue Composables

Vue composables that provide access to Directus app context including API client, stores, collections, and utility functions. These are essential for building extensions that integrate with the Directus admin interface.

Capabilities

System Context Access

Core system access composables for API, SDK, stores and extensions configuration.

/**
 * Provides access to the global Directus API client (Axios instance)
 * @returns AxiosInstance for making HTTP requests to Directus API
 * @throws Error if API client could not be found in injection context
 */
function useApi(): AxiosInstance;

/**
 * Provides access to the Directus SDK client with full type support
 * @returns DirectusClient with RestClient for typed API operations
 * @throws Error if SDK could not be found in injection context
 */
function useSdk<Schema extends object = any>(): DirectusClient<Schema> & RestClient<Schema>;

/**
 * Provides access to all Pinia stores used throughout the Directus application
 * @returns Object containing store factory functions (useUserStore, useCollectionsStore, etc.)
 * @throws Error if stores could not be found in injection context
 */
function useStores(): Record<string, any>;

/**
 * Provides access to the global extensions configuration
 * @returns RefRecord containing all registered app extensions and their configs
 * @throws Error if extensions config could not be found in injection context
 */
function useExtensions(): RefRecord<AppExtensionConfigs>;

Usage Examples:

import { useApi, useSdk, useStores, useExtensions } from '@directus/extensions-sdk';

export default defineComponent({
  setup() {
    // Access the Directus API client
    const api = useApi();
    
    // Access the typed SDK client
    const sdk = useSdk<MySchema>();
    
    // Access stores
    const { useUserStore, useCollectionsStore } = useStores();
    const userStore = useUserStore();
    const collectionsStore = useCollectionsStore();
    
    // Access extensions config
    const extensions = useExtensions();
    
    // Make API calls
    const fetchUsers = async () => {
      const response = await api.get('/users');
      return response.data;
    };
    
    // Use SDK for typed operations
    const fetchTypedItems = async () => {
      const items = await sdk.request(readItems('my_collection'));
      return items;
    };
    
    return {
      currentUser: userStore.currentUser,
      collections: collectionsStore.collections,
      fetchUsers,
      fetchTypedItems
    };
  }
});

Collection Management

Composable for working with Directus collections and their metadata.

/**
 * Provides utilities for working with Directus collections
 * @returns Collection management utilities and reactive collection data
 */
function useCollection(): CollectionHelpers;

interface CollectionHelpers {
  collections: Ref<Collection[]>;
  getCollection: (collection: string) => Collection | null;
  primaryKeyField: ComputedRef<Field | null>;
  isSingleton: ComputedRef<boolean>;
  // Additional collection utilities
  [key: string]: any;
}

Item Management

Composable for CRUD operations on collection items with reactive state management.

/**
 * Provides utilities for managing collection items with reactive state
 * @returns Item management utilities for CRUD operations
 */
function useItems(): ItemHelpers;

interface ItemHelpers {
  items: Ref<any[]>;
  loading: Ref<boolean>;
  error: Ref<any>;
  create: (item: any) => Promise<any>;
  update: (key: string | number, item: any) => Promise<any>;
  remove: (key: string | number) => Promise<void>;
  refresh: () => Promise<void>;
  // Additional item management utilities
  [key: string]: any;
}

Layout Management

Composable for working with layout configurations and layout-specific functionality.

/**
 * Provides utilities for managing layout configurations
 * @returns Layout management utilities and reactive layout data
 */
function useLayout(): LayoutHelpers;

interface LayoutHelpers {
  // Layout utilities and reactive data
  [key: string]: any;
}

Field Filtering

Composable for filtering and managing field visibility and permissions.

/**
 * Provides utilities for filtering fields based on permissions and context
 * @returns Field filtering utilities and reactive field data
 */
function useFilterFields(): FieldFilterHelpers;

interface FieldFilterHelpers {
  // Field filtering utilities and reactive data
  [key: string]: any;
}

Synchronization

Composable for handling data synchronization between components and stores.

/**
 * Provides utilities for synchronizing data between components and stores
 * @returns Synchronization utilities for reactive data management
 */
function useSync(): SyncHelpers;

interface SyncHelpers {
  // Synchronization utilities and reactive data
  [key: string]: any;
}

Common Usage Pattern:

import { 
  useApi, 
  useStores, 
  useCollection, 
  useItems 
} from '@directus/extensions-sdk';

export default defineComponent({
  setup() {
    const api = useApi();
    const { usePermissionsStore } = useStores();
    const collection = useCollection();
    const items = useItems();
    const permissionsStore = usePermissionsStore();
    
    // Use composables together for complex functionality
    const canCreateItems = computed(() => {
      return permissionsStore.hasPermission('create', collection.name);
    });
    
    return {
      canCreateItems,
      // ... other reactive properties
    };
  }
});

Type Definitions

Common types used by the composables:

interface Collection {
  collection: string;
  meta: {
    collection: string;
    icon: string;
    note: string;
    display_template: string;
    hidden: boolean;
    singleton: boolean;
    translations: any;
    archive_field: string;
    archive_app_filter: boolean;
    archive_value: string;
    unarchive_value: string;
    sort_field: string;
    accountability: string;
    color: string;
    item_duplication_fields: string[];
    sort: number;
    group: string;
    collapse: string;
    [key: string]: any;
  };
  schema: {
    name: string;
    comment: string;
    [key: string]: any;
  };
  fields: Field[];
}

interface Field {
  collection: string;
  field: string;
  type: string;
  meta: {
    id: number;
    collection: string;
    field: string;
    special: string[];
    interface: string;
    options: any;
    display: string;
    display_options: any;
    readonly: boolean;
    hidden: boolean;
    sort: number;
    width: string;
    translations: any;
    note: string;
    conditions: any;
    required: boolean;
    group: string;
    validation: any;
    validation_message: string;
    [key: string]: any;
  };
  schema: {
    name: string;
    table: string;
    data_type: string;
    default_value: any;
    max_length: number;
    numeric_precision: number;
    numeric_scale: number;
    is_nullable: boolean;
    is_unique: boolean;
    is_primary_key: boolean;
    is_generated: boolean;
    generation_expression: string;
    has_auto_increment: boolean;
    foreign_key_column: string;
    foreign_key_table: string;
    comment: string;
    [key: string]: any;
  };
}

interface RefRecord<T> {
  [key: string]: Ref<T>;
}

interface AppExtensionConfigs {
  interfaces: any[];
  displays: any[];
  layouts: any[];
  modules: any[];
  panels: any[];
  themes: any[];
  [key: string]: any;
}