# TypeScript SDK

The dcupl SDK is the in-memory query engine under dcupl: define typed models, load data from any source and query them in the browser or in Node.js, with relationships, indexing, facets and change events built in.

**npm**

```bash
npm install @dcupl/core
```

**yarn**

```bash
yarn add @dcupl/core
```

**pnpm**

```bash
pnpm add @dcupl/core
```

These docs describe `@dcupl/core` 2.1 and `@dcupl/cli` 2.0. The npm packages are published under the ISC license.

[Quick start](/sdk/quick-start)

[Playground](/playground)

## How it works

### Define models

Create typed schemas with properties, relationships, and validation rules. Models define the structure of your data and how each property is parsed, validated and indexed.

```typescript
dcupl.models.set({
  key: 'Product',
  properties: [
    { key: 'name', type: 'string' },
    { key: 'price', type: 'int' },
    { key: 'category', type: 'string' },
  ]
});
```

### Load data

Load data from inline arrays, fetch from APIs, or use the Loader with Console. Data is indexed automatically for fast queries.

```typescript
// Inline data
dcupl.data.set(products, {
  model: 'Product'
});

// Initialize and build indexes
await dcupl.init();
```

### Query instantly

Filter, sort, aggregate, and analyze your data. All queries run in memory, equality filters against inverse indexes — no server round-trips needed.

```typescript
const list = dcupl.lists.create({
  modelKey: 'Product'
});

// Add filters
list.catalog.query.addCondition({
  attribute: 'category',
  operator: 'eq',
  value: 'Electronics'
});

// Get results
const items = list.catalog.query.items();
```

## Key capabilities

### Data models

Typed schemas with validation rules and computed properties

### Relationships

Connect models via references — products to categories, orders to users

### Indexed queries

Equality filters (eq, in) use inverse indexes — no full scan, no server round-trip

### Analysis functions

Facets, aggregations, groupBy, pivot tables — built-in

### Real-time updates

Upsert, delete, refresh data — lists refresh and notify you on update()

### TypeScript first

TypeScript types included, IntelliSense, works with any framework

## Explore the SDK

The SDK docs are organized into three tracks. Start with Learn if you're new, jump to Build when you're applying dcupl to a real project, and use Reference to look up exact APIs.

### Learn

- [Quick start](/sdk/quick-start) — Build a working example in 5 minutes
- [Setup options](/sdk/setup-options) — Choose between SDK-only and Console + Loader setups
- [Core concepts](/sdk/core-concepts) — Models, data, lists, and the query engine
- [Querying](/sdk/queries/query-filter) — Filters, logic, ranges, search, and deep queries

### Build

- [Analysis functions](/sdk/fn/facets) — Facets, aggregations, groupBy, pivot, and suggestions
- [Advanced patterns](/sdk/advanced/faceted-search) — Faceted search, master–detail, infinite scroll, realtime
- [Guides](/sdk/guides/typescript) — TypeScript, testing, debugging, deployment, scripts, and common mistakes
- [Performance & caching](/sdk/advanced/performance) — Tune indexing, memoization, and data loading for large datasets

### Reference

- [API reference](/sdk/api) — Every class, method, and type exported by @dcupl/core
- [Quick reference](/sdk/reference) — One-page cheatsheet for the most common SDK calls
