Catalog API
The Catalog API (list.catalog) provides powerful querying, filtering, and analytical functions for working with data in a list. It's the primary interface for retrieving and analyzing data.
Overview
Each list has its own catalog instance that maintains independent query state and provides access to:
- Query operations: Apply, execute, and manage filters
- Analytical functions: Facets, aggregations, pivot tables, grouping, suggestions
- Data retrieval: Get items with projection and sorting
API Namespaces
catalog.query
Main query interface for filtering and retrieving data.
See: Query Operations
catalog.fn
Analytical functions for data analysis.
See: Analytical Functions
catalog.filters
Legacy filter interface (deprecated, use catalog.query instead).
Query Operations
addCondition()
Adds query condition(s) to the catalog. Use this to filter data.
Signature:
addCondition(
condition: DcuplQuery | DcuplQuery[],
options?: { skipProcessing?: boolean }
): DcuplGlobalQueryOptionsParameters:
| Parameter | Type | Required | Description |
|---|---|---|---|
condition |
DcuplQuery | DcuplQuery[] |
Yes | Query condition(s) to add |
options.skipProcessing |
boolean |
No | Skip immediate query processing |
Returns: DcuplGlobalQueryOptions - Current query state
Examples:
list.catalog.query.addCondition({
operator: 'eq',
attribute: 'status',
value: 'active',
});list.catalog.query.addCondition([
{ operator: 'eq', attribute: 'status', value: 'active' },
{ operator: 'gte', attribute: 'price', value: 100 },
]);list.catalog.query.addCondition({
operator: 'eq',
attribute: 'category',
value: { key: 'electronics' },
queryKey: 'categoryFilter',
});setCondition()
Replaces all existing conditions with new condition(s).
Signature:
setCondition(
condition: DcuplQuery | DcuplQuery[],
options?: { skipProcessing?: boolean }
): DcuplGlobalQueryOptionsParameters:
| Parameter | Type | Required | Description |
|---|---|---|---|
condition |
DcuplQuery | DcuplQuery[] |
Yes | Query condition(s) to set |
options.skipProcessing |
boolean |
No | Skip immediate query processing |
Returns: DcuplGlobalQueryOptions - Current query state
Examples:
list.catalog.query.setCondition({
operator: 'eq',
attribute: 'status',
value: 'active',
});list.catalog.query.setCondition([
{ operator: 'eq', attribute: 'status', value: 'active' },
{ operator: 'gte', attribute: 'price', value: 100 },
]);addGroup()
Adds a query group with multiple conditions combined by AND/OR logic.
Signature:
addGroup(
group: DcuplQueryGroup,
options?: { skipProcessing?: boolean }
): DcuplGlobalQueryOptionsParameters:
| Parameter | Type | Required | Description |
|---|---|---|---|
group |
DcuplQueryGroup |
Yes | Query group to add |
options.skipProcessing |
boolean |
No | Skip immediate query processing |
Returns: DcuplGlobalQueryOptions - Current query state
Examples:
list.catalog.query.addGroup({
groupKey: 'priceRange',
groupType: 'and',
queries: [
{ operator: 'gte', attribute: 'price', value: 50 },
{ operator: 'lte', attribute: 'price', value: 200 },
],
});list.catalog.query.addGroup({
groupKey: 'categories',
groupType: 'or',
queries: [
{ operator: 'eq', attribute: 'category', value: { key: 'electronics' } },
{ operator: 'eq', attribute: 'category', value: { key: 'books' } },
],
});items()
Executes the current query and returns matching items.
Signature:
items<T>(options?: DcuplListQueryOptions<T>): T[]Parameters:
| Parameter | Type | Required | Description |
|---|---|---|---|
options |
DcuplListQueryOptions |
No | Query execution options |
Returns: T[] - Array of matching items
Examples:
const items = list.catalog.query.items();const page = list.catalog.query.items({
start: 0,
count: 20,
});const sorted = list.catalog.query.items({
sort: { price: 'desc', name: 'asc' },
});const projected = list.catalog.query.items({
projection: {
name: true,
price: true,
category: true,
},
});const results = list.catalog.query.items({
queries: [{ operator: 'eq', attribute: 'status', value: 'active' }],
start: 0,
count: 20,
sort: { price: 'desc' },
projection: { name: true, price: true },
});first()
Returns the first matching item.
Signature:
first<T>(options?: DcuplListQueryOptions<T>): T | undefinedParameters:
| Parameter | Type | Required | Description |
|---|---|---|---|
options |
DcuplListQueryOptions |
No | Query execution options |
Returns: T | undefined - First matching item or undefined
Examples:
const item = list.catalog.query.first();const activeItem = list.catalog.query.first({
queries: [{ operator: 'eq', attribute: 'status', value: 'active' }],
});count()
Returns the count of matching items.
Signature:
count<T>(options?: DcuplListQueryOptions<T>): numberParameters:
| Parameter | Type | Required | Description |
|---|---|---|---|
options |
DcuplListQueryOptions |
No | Query execution options |
Returns: number - Count of matching items
Examples:
const total = list.catalog.query.count();const activeCount = list.catalog.query.count({
queries: [{ operator: 'eq', attribute: 'status', value: 'active' }],
});any()
Checks if any results exist.
Signature:
any<T>(options?: DcuplListQueryOptions<T>): booleanParameters:
| Parameter | Type | Required | Description |
|---|---|---|---|
options |
DcuplListQueryOptions |
No | Query execution options |
Returns: boolean - True if any results exist
Examples:
if (list.catalog.query.any()) {
console.log('Items found');
}const hasActive = list.catalog.query.any({
queries: [{ operator: 'eq', attribute: 'status', value: 'active' }],
});removeCondition()
Removes specific query condition(s).
Signature:
removeCondition(
condition: DcuplQuery | DcuplQuery[],
options?: { skipProcessing?: boolean }
): DcuplGlobalQueryOptionsParameters:
| Parameter | Type | Required | Description |
|---|---|---|---|
condition |
DcuplQuery | DcuplQuery[] |
Yes | Condition(s) to remove |
options.skipProcessing |
boolean |
No | Skip immediate query processing |
Returns: DcuplGlobalQueryOptions - Updated query state
Examples:
list.catalog.query.removeCondition({
queryKey: 'statusFilter',
});list.catalog.query.removeCondition({
attribute: 'status',
});list.catalog.query.removeCondition([{ attribute: 'status' }, { attribute: 'category' }]);removeGroup()
Removes a query group by its key.
Signature:
removeGroup(
groupKey: string,
options?: { skipProcessing?: boolean }
): DcuplGlobalQueryOptionsParameters:
| Parameter | Type | Required | Description |
|---|---|---|---|
groupKey |
string |
Yes | Key of the group to remove |
options.skipProcessing |
boolean |
No | Skip immediate query processing |
Returns: DcuplGlobalQueryOptions - Updated query state
Examples:
list.catalog.query.removeGroup('priceRange');clear()
Clears all query conditions.
Signature:
clear(options?: { skipProcessing?: boolean }): DcuplGlobalQueryOptionsParameters:
| Parameter | Type | Required | Description |
|---|---|---|---|
options.skipProcessing |
boolean |
No | Skip immediate query processing |
Returns: DcuplGlobalQueryOptions - Empty query state
Examples:
list.catalog.query.clear();list.catalog.query.clear({ skipProcessing: true });list.catalog.query.clear();
const allItems = list.catalog.query.items();current()
Returns the current query state.
Signature:
current(): DcuplGlobalQueryOptionsReturns: DcuplGlobalQueryOptions - Current query configuration
Examples:
const query = list.catalog.query.current();
console.log(query.queries);
console.log(query.groupType);const savedQuery = list.catalog.query.current();list.catalog.query.setCondition(savedQuery.queries);isEmpty()
Checks if the query has any conditions.
Signature:
isEmpty(): booleanReturns: boolean - True if no conditions are applied
Examples:
if (list.catalog.query.isEmpty()) {
console.log('No filters applied');
}has()
Checks if a specific query or group exists.
Signature:
has(options: { groupKey: string; queryKey?: string }): booleanParameters:
| Parameter | Type | Required | Description |
|---|---|---|---|
options.groupKey |
string |
Yes | Group key to check |
options.queryKey |
string |
No | Optional query key within group |
Returns: boolean - True if exists
Examples:
if (list.catalog.query.has({ groupKey: 'priceRange' })) {
console.log('Price range filter is active');
}if (
list.catalog.query.has({
groupKey: 'filters',
queryKey: 'status',
})
) {
console.log('Status filter is active');
}applyOptions()
Applies item options (pagination, sorting, projection) to the query state. This method sets or updates the non-filter options that affect how results are retrieved.
Signature:
applyOptions(
itemOptions: DcuplItemsOptions,
options?: { mode?: 'set' | 'update'; skipProcessing?: boolean }
): DcuplGlobalQueryOptionsParameters:
| Parameter | Type | Required | Description |
|---|---|---|---|
itemOptions |
DcuplItemsOptions |
Yes | Item options including start, count, projection, and sort |
options.mode |
'set' | 'update' |
No | 'set' replaces all options, 'update' merges with existing (default: 'set') |
options.skipProcessing |
boolean |
No | Skip immediate query processing |
DcuplItemsOptions:
| Property | Type | Description |
|---|---|---|
start |
number |
Starting index for pagination |
count |
number |
Number of items to return |
projection |
Projection |
Fields to include in results |
sort |
SortingProjection |
Sorting configuration |
Returns: DcuplGlobalQueryOptions - Updated query state
Examples:
list.catalog.query.applyOptions({
start: 0,
count: 20,
});list.catalog.query.applyOptions({
sort: { price: 'desc', name: 'asc' },
});list.catalog.query.applyOptions({
projection: {
name: true,
price: true,
category: true,
},
});list.catalog.query.applyOptions({
start: 0,
count: 20,
sort: { price: 'desc' },
projection: { name: true, price: true, category: true },
});// First set initial options
list.catalog.query.applyOptions({
start: 0,
count: 20,
});
// Later, update only the sorting (keeps start and count)
list.catalog.query.applyOptions(
{ sort: { price: 'desc' } },
{ mode: 'update' }
);// Set new options, clearing any previously set options
list.catalog.query.applyOptions(
{ count: 50 },
{ mode: 'set' }
);// Apply multiple changes without intermediate processing
list.catalog.query.addCondition(
{ operator: 'eq', attribute: 'status', value: 'active' },
{ skipProcessing: true }
);
list.catalog.query.applyOptions({
start: 0,
count: 20,
sort: { createdAt: 'desc' },
});
// Processing happens on the final callone()
Returns a single item by key.
Signature:
one<T>(options: DcuplItemOptions<T>): T | undefinedParameters:
| Parameter | Type | Required | Description |
|---|---|---|---|
options |
DcuplItemOptions |
Yes | Item retrieval options |
Returns: T | undefined - The item or undefined if not found
Examples:
const item = list.catalog.query.one({ itemKey: 'p1' });const item = list.catalog.query.one({
itemKey: 'p1',
projection: { name: true, price: true },
});many()
Returns multiple specific items by keys.
Signature:
many<T>(options: DcuplManyItemsOptions<T>): T[]Parameters:
| Parameter | Type | Required | Description |
|---|---|---|---|
options |
DcuplManyItemsOptions |
Yes | Items retrieval options |
Returns: T[] - Array of items
Examples:
const items = list.catalog.query.many({
itemKeys: ['p1', 'p2', 'p3'],
});const items = list.catalog.query.many({
itemKeys: ['p1', 'p2', 'p3'],
projection: { name: true, price: true },
});Core Query Methods
These are the foundational query methods. The semantic aliases (like addCondition, clear, items) provide a more intuitive API built on top of these core methods.
apply()
Applies query condition(s) to the catalog. This is the core method that addCondition(), setCondition(), and addGroup() are built on.
Signature:
apply(
query: DcuplQueryGroup | DcuplQuery | DcuplQuery[] | DcuplQueryGroup[],
options?: { mode?: 'set' | 'add'; skipProcessing?: boolean }
): DcuplGlobalQueryOptionsParameters:
| Parameter | Type | Required | Description |
|---|---|---|---|
query |
DcuplQueryGroup | DcuplQuery | DcuplQuery[] | DcuplQueryGroup[] |
Yes | Query condition(s) or group(s) to apply |
options.mode |
'set' | 'add' |
No | 'set' replaces existing queries, 'add' appends (default: 'set') |
options.skipProcessing |
boolean |
No | Skip immediate query processing |
Returns: DcuplGlobalQueryOptions - Updated query state
Examples:
list.catalog.query.apply(
{ operator: 'eq', attribute: 'status', value: 'active' },
{ mode: 'add' }
);list.catalog.query.apply(
{ operator: 'eq', attribute: 'status', value: 'active' },
{ mode: 'set' }
);list.catalog.query.apply([
{ operator: 'eq', attribute: 'status', value: 'active' },
{ operator: 'gte', attribute: 'price', value: 100 },
], { mode: 'add' });list.catalog.query.apply({
groupKey: 'priceRange',
groupType: 'and',
queries: [
{ operator: 'gte', attribute: 'price', value: 50 },
{ operator: 'lte', attribute: 'price', value: 200 },
],
}, { mode: 'add' });remove()
Removes query condition(s) or groups from the catalog. This is the core method that removeCondition() and removeGroup() are built on.
Signature:
remove(options?: Partial<DcuplQueryGroup> | DcuplQuery): DcuplGlobalQueryOptionsParameters:
| Parameter | Type | Required | Description |
|---|---|---|---|
options |
Partial |
No | Condition or group to remove. If omitted, removes all. |
Returns: DcuplGlobalQueryOptions - Updated query state
Examples:
list.catalog.query.remove({ queryKey: 'statusFilter' });list.catalog.query.remove({ attribute: 'status' });list.catalog.query.remove({ groupKey: 'priceRange' });list.catalog.query.remove();reset()
Resets the query to its initial empty state. This is the core method that clear() wraps.
Signature:
reset(options?: { skipProcessing?: boolean }): DcuplGlobalQueryOptionsParameters:
| Parameter | Type | Required | Description |
|---|---|---|---|
options.skipProcessing |
boolean |
No | Skip immediate query processing |
Returns: DcuplGlobalQueryOptions - Empty query state
Examples:
list.catalog.query.reset();list.catalog.query.reset({ skipProcessing: true });execute()
Executes the current query and returns matching items. This is the core method that items() wraps.
Signature:
execute<T>(options?: DcuplListQueryOptions<T>): T[]Parameters:
| Parameter | Type | Required | Description |
|---|---|---|---|
options |
DcuplListQueryOptions |
No | Query execution options |
Returns: T[] - Array of matching items
Examples:
const items = list.catalog.query.execute();const items = list.catalog.query.execute({
start: 0,
count: 20,
sort: { price: 'desc' },
});const items = list.catalog.query.execute({
queries: [{ operator: 'eq', attribute: 'featured', value: true }],
count: 10,
});get()
Returns the current query state. This is the core method that current() wraps.
Signature:
get(): DcuplGlobalQueryOptionsReturns: DcuplGlobalQueryOptions - Current query configuration
Examples:
const query = list.catalog.query.get();
console.log(query.queries);const savedQuery = list.catalog.query.get();
// ... make changes ...
list.catalog.query.apply(savedQuery.queries, { mode: 'set' });Analytical Functions
facets()
Computes facet values for an attribute (filter options with counts).
Signature:
facets(options: DcuplFacetOptions): DcuplFacet[]Parameters:
| Parameter | Type | Required | Description |
|---|---|---|---|
options |
DcuplFacetOptions |
Yes | Facet computation options |
Returns: DcuplFacet[] - Array of facet entries
Examples:
const categories = list.catalog.fn.facets({
attribute: 'category',
});const topCategories = list.catalog.fn.facets({
attribute: 'category',
count: 10,
});const activeFacets = list.catalog.fn.facets({
attribute: 'category',
excludeZeros: true,
});const facets = list.catalog.fn.facets({
attribute: 'category',
calculateResults: true,
});const manufacturerFacets = list.catalog.fn.facets({
attribute: 'category.manufacturer',
});aggregate()
Performs aggregation operations on an attribute.
Signature:
aggregate(options: AggregationOptions): AggregationParameters:
| Parameter | Type | Required | Description |
|---|---|---|---|
options |
AggregationOptions |
Yes | Aggregation configuration |
Returns: Aggregation - Aggregation results
Examples:
const stats = list.catalog.fn.aggregate({
attribute: 'price',
types: ['sum', 'avg', 'min', 'max', 'count'],
});
console.log(stats.sum, stats.avg, stats.min, stats.max, stats.count);const itemCount = list.catalog.fn.aggregate({
attribute: 'key',
types: ['count'],
});const distinctCategories = list.catalog.fn.aggregate({
attribute: 'category',
types: ['distinct'],
distinctOptions: {
limit: 20,
skipKeys: false,
},
});const priceGroups = list.catalog.fn.aggregate({
attribute: 'price',
types: ['group'],
groupOptions: {
groups: [
{ from: 0, to: 50 },
{ from: 50, to: 100 },
{ from: 100, to: 200 },
],
calculateNotFound: true,
},
});const cleanStats = list.catalog.fn.aggregate({
attribute: 'price',
types: ['sum', 'avg'],
excludeZeros: true,
excludeUndefineds: true,
});suggest()
Provides autocomplete suggestions for an attribute.
Signature:
suggest(options: SuggestionOptions): Suggestion[]Parameters:
| Parameter | Type | Required | Description |
|---|---|---|---|
options |
SuggestionOptions |
Yes | Suggestion configuration |
Returns: Suggestion[] - Array of suggestions
Examples:
const suggestions = list.catalog.fn.suggest({
attribute: 'name',
value: 'prod',
});const topSuggestions = list.catalog.fn.suggest({
attribute: 'name',
value: 'prod',
max: 10,
});const suggestions = list.catalog.fn.suggest({
attribute: 'name',
value: 'prod',
transform: ['lowercase'],
});const quickSuggestions = list.catalog.fn.suggest({
attribute: 'name',
value: 'prod',
calculateResultKeys: false,
});const allSuggestions = list.catalog.fn.suggest({
attribute: 'name',
value: 'prod',
relevantData: 'all',
});const otherSuggestions = list.catalog.fn.suggest({
attribute: 'category',
value: 'elect',
relevantData: 'excludeQuery',
excludeQuery: { attribute: 'category' },
});groupBy()
Groups items by an attribute value.
Signature:
groupBy(options: DcuplGroupByOptions): GroupByResponseParameters:
| Parameter | Type | Required | Description |
|---|---|---|---|
options |
DcuplGroupByOptions |
Yes | Grouping configuration |
Returns: GroupByResponse - Grouped items
Examples:
const grouped = list.catalog.fn.groupBy({
primaryAttribute: 'category',
});const groupedWithStats = list.catalog.fn.groupBy({
primaryAttribute: 'category',
aggregates: [{ attribute: 'price', types: ['sum', 'avg'] }],
});const sortedGroups = list.catalog.fn.groupBy({
primaryAttribute: 'category',
sort: { count: 'desc' },
});const nestedGroups = list.catalog.fn.groupBy({
primaryAttribute: 'category.parent',
});pivot()
Creates a pivot table from the data.
Signature:
pivot(options: PivotOptions): PivotResponseParameters:
| Parameter | Type | Required | Description |
|---|---|---|---|
options |
PivotOptions |
Yes | Pivot table configuration |
Returns: PivotResponse - Pivot table structure
Examples:
const pivot = list.catalog.fn.pivot({
rows: [{ attribute: 'category' }],
columns: [{ attribute: 'status' }],
values: [{ attribute: 'price', types: ['sum'] }],
});const complexPivot = list.catalog.fn.pivot({
rows: [{ attribute: 'category' }, { attribute: 'manufacturer' }],
columns: [{ attribute: 'status' }, { attribute: 'featured' }],
values: [
{ attribute: 'price', types: ['sum', 'avg'] },
{ attribute: 'quantity', types: ['sum'] },
],
});const deepPivot = list.catalog.fn.pivot({
rows: [{ attribute: 'category.parent' }],
columns: [{ attribute: 'manufacturer.country' }],
values: [{ attribute: 'price', types: ['sum'] }],
});metadata()
Returns metadata about the list and its data.
Signature:
metadata(): ListMetadataReturns: ListMetadata - List metadata
Examples:
const meta = list.catalog.fn.metadata();
console.log(meta.key); // Model key
console.log(meta.currentSize); // Filtered item count
console.log(meta.initialSize); // Total item count
console.log(meta.attributes); // Model attributes
console.log(meta.views); // Available views
console.log(meta.appliedQuery); // Current queryType Definitions
DcuplQuery
Single query condition.
Type Definition:
type DcuplQuery = {
operator: DcuplQueryOperator;
attribute: string;
value: any;
queryKey?: any;
options?: {
transform?: DcuplQueryTransformOptions[];
invert?: boolean;
arrayValueHandling?: 'some' | 'every';
};
};Operators:
| Operator | Description | Value Type |
|---|---|---|
'eq' |
Equals | any |
'find' |
Contains/Search | string | object |
'gt' |
Greater than | number | Date | string |
'gte' |
Greater than or equal | number | Date | string |
'lt' |
Less than | number | Date | string |
'lte' |
Less than or equal | number | Date | string |
'typeof' |
Type check | string |
'isTruthy' |
Truthiness check | boolean |
'size' |
Array/string length | number |
Examples:
{ operator: 'eq', attribute: 'status', value: 'active' }{ operator: 'find', attribute: 'name', value: 'search term' }{ operator: 'gte', attribute: 'price', value: 100 }
{ operator: 'lt', attribute: 'quantity', value: 10 }{ operator: 'typeof', attribute: 'data', value: 'object' }{ operator: 'isTruthy', attribute: 'featured', value: true }{ operator: 'size', attribute: 'tags', value: 3 }{
operator: 'eq',
attribute: 'name',
value: 'john',
options: { transform: ['lowercase'] }
}{
operator: 'eq',
attribute: 'tags',
value: 'featured',
options: { arrayValueHandling: 'some' }
}{
operator: 'eq',
attribute: 'status',
value: 'active',
options: { invert: true }
}DcuplQueryGroup
Group of query conditions with combination logic.
Type Definition:
type DcuplQueryGroup = {
groupType?: 'and' | 'or';
groupKey?: string;
queries: Array<DcuplQuery | DcuplQueryGroup>;
};Examples:
{
groupType: 'and',
groupKey: 'activeProducts',
queries: [
{ operator: 'eq', attribute: 'status', value: 'active' },
{ operator: 'gte', attribute: 'price', value: 100 }
]
}{
groupType: 'or',
queries: [
{ operator: 'eq', attribute: 'category', value: { key: 'cat1' } },
{ operator: 'eq', attribute: 'category', value: { key: 'cat2' } }
]
}{
groupType: 'and',
queries: [
{ operator: 'eq', attribute: 'status', value: 'active' },
{
groupType: 'or',
queries: [
{ operator: 'eq', attribute: 'featured', value: true },
{ operator: 'gte', attribute: 'rating', value: 4.5 }
]
}
]
}DcuplListQueryOptions
Query execution options.
Type Definition:
type DcuplListQueryOptions<T> = {
queries?: Array<DcuplQuery | DcuplQueryGroup>;
groupType?: 'and' | 'or';
start?: number;
count?: number;
projection?: Projection<T>;
sort?: SortingProjection<T>;
};Examples:
{
start: 0,
count: 20
}{
sort: { price: 'desc', name: 'asc' }
}{
projection: {
name: true,
price: true,
category: true
}
}{
queries: [
{ operator: 'eq', attribute: 'status', value: 'active' }
],
groupType: 'and',
start: 0,
count: 20,
sort: { price: 'desc' },
projection: { name: true, price: true }
}DcuplFacetOptions
Facet computation options.
Type Definition:
type DcuplFacetOptions = {
attribute: string;
count?: number;
excludeZeros?: boolean;
excludeUndefineds?: boolean;
excludeUnresolved?: boolean;
calculateResults?: boolean;
};Examples:
{
attribute: 'category';
}{
attribute: 'category',
count: 10,
excludeZeros: true,
excludeUndefineds: true,
calculateResults: true
}AggregationOptions
Aggregation configuration.
Type Definition:
type AggregationOptions = {
attribute: string;
types: AggregationType[];
distinctOptions?: {
limit?: number;
skipKeys?: boolean;
};
groupOptions?: {
limit?: number;
calculateNotFound?: boolean;
groups?: AggregationGroupOption[];
};
excludeZeros?: boolean;
excludeUndefineds?: boolean;
excludeUnresolved?: boolean;
};
type AggregationType = 'sum' | 'avg' | 'count' | 'min' | 'max' | 'distinct' | 'group';Examples:
{
attribute: 'price',
types: ['sum', 'avg', 'min', 'max']
}{
attribute: 'category',
types: ['distinct'],
distinctOptions: { limit: 20 }
}{
attribute: 'price',
types: ['group'],
groupOptions: {
groups: [
{ from: 0, to: 50 },
{ from: 50, to: 100 }
]
}
}SuggestionOptions
Autocomplete suggestion options.
Type Definition:
type SuggestionOptions = {
attribute: string;
value: any;
max?: number;
calculateResultKeys?: boolean;
excludeUndefineds?: boolean;
excludeNulls?: boolean;
transform?: DcuplQueryTransformOptions[];
relevantData?: 'filtered' | 'all' | 'excludeQuery';
excludeQuery?: Partial<DcuplQuery | DcuplQueryGroup>;
};Examples:
{
attribute: 'name',
value: 'prod'
}{
attribute: 'name',
value: 'prod',
max: 10,
transform: ['lowercase'],
relevantData: 'all'
}PivotOptions
Pivot table configuration.
Type Definition:
type PivotOptions = {
rows: Array<{ attribute: string }>;
columns: Array<{ attribute: string }>;
values: Array<{
attribute: string;
types: AggregationType[];
}>;
};Examples:
{
rows: [{ attribute: 'category' }],
columns: [{ attribute: 'status' }],
values: [{ attribute: 'price', types: ['sum', 'avg'] }]
}Complete Examples
Product Search with Facets
const productList = dcupl.lists.create({ modelKey: 'Product' });
// Add search query
productList.catalog.query.addCondition({
operator: 'find',
attribute: 'name',
value: searchTerm,
options: { transform: ['lowercase'] },
});
// Get facets for filters
const categories = productList.catalog.fn.facets({
attribute: 'category',
excludeZeros: true,
});
const manufacturers = productList.catalog.fn.facets({
attribute: 'manufacturer',
excludeZeros: true,
});
// Add category filter
productList.catalog.query.addCondition({
operator: 'eq',
attribute: 'category',
value: { key: selectedCategory },
queryKey: 'categoryFilter',
});
// Get results
const results = productList.catalog.query.items({
start: 0,
count: 20,
sort: { relevance: 'desc', name: 'asc' },
});Price Range Filter
// Add price range as group
productList.catalog.query.addGroup({
groupKey: 'priceRange',
groupType: 'and',
queries: [
{ operator: 'gte', attribute: 'price', value: minPrice },
{ operator: 'lte', attribute: 'price', value: maxPrice },
],
});
// Update range
productList.catalog.query.removeGroup('priceRange');
productList.catalog.query.addGroup({
groupKey: 'priceRange',
groupType: 'and',
queries: [
{ operator: 'gte', attribute: 'price', value: newMinPrice },
{ operator: 'lte', attribute: 'price', value: newMaxPrice },
],
});
// Clear range
productList.catalog.query.removeGroup('priceRange');Statistics Dashboard
// Get overall statistics
const stats = productList.catalog.fn.aggregate({
attribute: 'price',
types: ['sum', 'avg', 'min', 'max', 'count'],
});
// Group by category
const categoryStats = productList.catalog.fn.groupBy({
primaryAttribute: 'category',
aggregates: [
{ attribute: 'price', types: ['sum', 'avg'] },
{ attribute: 'quantity', types: ['sum'] },
],
});
// Pivot by category and status
const pivot = productList.catalog.fn.pivot({
rows: [{ attribute: 'category' }],
columns: [{ attribute: 'status' }],
values: [
{ attribute: 'price', types: ['sum'] },
{ attribute: 'quantity', types: ['count'] },
],
});Autocomplete Search
function autocomplete(query: string) {
const suggestions = productList.catalog.fn.suggest({
attribute: 'name',
value: query,
max: 10,
transform: ['lowercase'],
relevantData: 'all',
});
return suggestions.map((s) => ({
label: s.value,
count: s.keys.length,
}));
}