OSS-first docs

These docs teach the open system first: contracts, generated surfaces, runtimes, governance, and incremental adoption. Studio shows up as the operating layer on top, not as the source of truth.

AI index

DataViews

A DataViewSpec describes how data should be queried, filtered, sorted, and presented to users. Runtime adapters execute optimized database queries and serve list views, detail views, and search interfaces while respecting policy constraints.

Core concepts

Data sources

A DataView connects to one or more data sources—databases, APIs, or other capabilities. You specify the source and the fields you want to expose.

Filtering

Define filters that users can apply to narrow down results. Filters can be simple (e.g., "status equals 'active'") or complex (e.g., "created within the last 30 days AND assigned to current user").

Sorting

Specify which fields can be sorted and the default sort order. ContractSpec generates efficient database queries with proper indexes.

Pagination

DataViews automatically support pagination to handle large datasets. You can configure page size limits and cursor-based or offset-based pagination.

Aggregations

Compute aggregates like counts, sums, averages, and group-by operations. These are useful for dashboards and summary views.

Example DataViewSpec

Here's a DataView for listing orders in TypeScript:

import { defineDataView } from '@contractspec/lib.contracts-spec';
import { SchemaModel, ScalarTypeEnum } from '@contractspec/lib.schema';

export const OrderList = defineDataView({
  meta: {
    key: 'order.list',
    version: '1.0.0',
    description: 'List of recent orders',
  },
  source: {
    type: 'database',
    table: 'orders',
  },
  fields: [
    { name: 'orderId', type: 'uuid', sortable: true },
    { name: 'customerName', type: 'string', searchable: true },
    { name: 'total', type: 'number', sortable: true },
    { 
      name: 'status', 
      type: 'enum', 
      values: ['pending', 'processing', 'shipped'],
      filterable: true 
    },
    { 
      name: 'createdAt', 
      type: 'timestamp', 
      sortable: true, 
      defaultSort: 'desc' 
    },
  ],
  filters: [
    { name: 'status', field: 'status', operator: 'in' },
    { name: 'dateRange', field: 'createdAt', operator: 'between' },
    { name: 'minTotal', field: 'total', operator: 'gte' },
  ],
  pagination: {
    type: 'cursor',
    defaultPageSize: 50,
    maxPageSize: 200,
  },
});

Policy integration

DataViews automatically enforce PolicySpecs. If a user doesn't have permission to see certain fields, those fields are automatically filtered out or redacted. If a user can only see their own data, the query is automatically scoped.

This means you define the data view once, and it works correctly for all users based on their permissions—no need to write separate queries for different roles.

Served outputs

From a DataViewSpec, ContractSpec serves:

  • Database queries – Optimized SQL or NoSQL queries executed at runtime
  • API endpoints – RESTful or GraphQL endpoints for fetching data
  • UI components – List views, tables, cards, and detail views
  • Search interfaces – Full-text search with autocomplete
  • Export functions – CSV, JSON, or Excel exports

Best practices

  • Only expose fields that users actually need—this improves performance and security.
  • Use appropriate indexes for sortable and filterable fields.
  • Set reasonable pagination limits to prevent performance issues.
  • Use aggregations sparingly—they can be expensive on large datasets.
  • Test DataViews with realistic data volumes to ensure they perform well.
OSS docscore-modelStart with OSS. Adopt Studio when you want the operating layer.

Why ContractSpec

Keep educational and comparison content reachable without letting it define the primary OSS learning path.