import { DcuplFiltersOptions, DcuplItemOptions, DcuplItemsOptions, DcuplGroupByOptions, FilterItem, ListItem, ListMetadata, GroupByResponse, DcuplFacetOptions, DcuplGlobalQueryOptions, DcuplQueryGroup, DcuplQuery, DcuplFilterOptions, ChangeDetector, DcuplListQueryOptions, AggregationOptions, Aggregation, DcuplManyItemsOptions, SuggestionOptions, Suggestion, PivotOptions, PivotResponse, IndicesController, DcuplFacet } from '@dcupl/common'; import { DcuplModel } from '../model-parser/index.js'; import { Filter } from './filter/filter.js'; import { DcuplApi } from '../dcupl/dcupl-api.js'; export declare class CatalogApi { protected dcuplApi: DcuplApi; protected cdRef: ChangeDetector; protected indicesController: IndicesController; protected metadata: ListMetadata; protected model: DcuplModel; protected filter: Filter; private itemService; private log; constructor(dcuplApi: DcuplApi, cdRef: ChangeDetector, indicesController: IndicesController); protected initListeners(): void; private initListMetadata; private getModelAttributes; query: { apply: (query: DcuplQueryGroup | DcuplQuery | DcuplQuery[] | DcuplQueryGroup[], options?: { mode?: "set" | "add"; skipProcessing?: boolean; }) => DcuplGlobalQueryOptions; applyOptions: (itemOptions: DcuplItemsOptions, options?: { mode?: "set" | "update"; skipProcessing?: boolean; }) => DcuplGlobalQueryOptions; remove: (options?: Partial | DcuplQuery) => DcuplGlobalQueryOptions; reset: (options?: { skipProcessing?: boolean; }) => DcuplGlobalQueryOptions; execute: (query?: DcuplListQueryOptions>) => ItemType[]; /** The item with `itemKey` among the list's current items, or `null` when there is none. */ one: (options: DcuplItemOptions) => ListType | null; many: (options: DcuplManyItemsOptions) => ListType[]; get: () => DcuplGlobalQueryOptions; has: (options: { groupKey: string; queryKey?: string; }) => boolean; /** * Add query condition(s) to the current query. * Accepts single condition or array of conditions. * Each condition is added to the group whose groupKey equals its attribute, found at any * nesting depth with a top-level match first (#302), or to a new top-level `'or'` group * if there is none. To combine conditions in an unkeyed * group, use `addGroup` — unkeyed groups are always appended, never merged. * Clearer alternative to `apply(condition, { mode: 'add' })`. * * @param condition - Single query condition or array of conditions to add * @param options - Optional processing options * @returns Updated query * * @example * ```typescript * // Add single condition * list.catalog.query.addCondition({ operator: 'eq', attribute: 'status', value: 'active' }); * * // Add multiple conditions * list.catalog.query.addCondition([ * { operator: 'eq', attribute: 'status', value: 'active' }, * { operator: 'gte', attribute: 'price', value: 100 } * ]); * ``` */ addCondition: (condition: DcuplQuery | DcuplQuery[], options?: { skipProcessing?: boolean; }) => DcuplGlobalQueryOptions; /** * Replace the conditions of an attribute group with new condition(s). * Accepts single condition or array of conditions. Each condition replaces the * conditions of the group keyed by its attribute; other groups are kept. The attribute * group is found at any nesting depth, a top-level match first (#302). * Clearer alternative to `apply(condition, { mode: 'set' })`. * * @param condition - Single query condition or array of conditions to set * @param options - Optional processing options * @returns Updated query * * @example * ```typescript * // Replace with single condition * list.catalog.query.setCondition({ operator: 'eq', attribute: 'status', value: 'active' }); * * // Replace with multiple conditions * list.catalog.query.setCondition([ * { operator: 'eq', attribute: 'status', value: 'active' }, * { operator: 'gte', attribute: 'price', value: 100 } * ]); * ``` */ setCondition: (condition: DcuplQuery | DcuplQuery[], options?: { skipProcessing?: boolean; }) => DcuplGlobalQueryOptions; /** * Add a query group to the filter. * - Keyed group (`groupKey` set): if a group with the same groupKey exists, its queries * are extended and its groupType is replaced by the given one (if set); otherwise a new * group is created. The existing group is found at any nesting depth, a top-level match * first, so a group nested in a keyless wrapper is extended where it is (#302). * - Unkeyed group (no `groupKey`): always appended as a new group; it is never merged * into another group, so each unkeyed group keeps its own groupType. * * A newly created group without `groupType` is stored as `'or'`. * * @param group - Query group to add * @param options - Optional processing options * @returns Updated query * * @example * ```typescript * list.catalog.query.addGroup({ * groupKey: 'priceRange', * groupType: 'and', * queries: [ * { operator: 'gte', attribute: 'price', value: 50 }, * { operator: 'lte', attribute: 'price', value: 100 } * ] * }); * ``` */ addGroup: (group: DcuplQueryGroup, options?: { skipProcessing?: boolean; }) => DcuplGlobalQueryOptions; /** * Replace one query group by key (per-group `set`). * The group with the same `groupKey` is replaced; other groups and the query options * are kept. Only `apply({ groupKey: 'root', ... }, { mode: 'set' })` replaces the whole * query. A keyed group passed inside a keyless wrapper group stays nested there and is * still found by `groupKey` by `removeGroup`, `has`, `filters.get` and `fn.facets` * (#294). A later `setGroup` with that key replaces the nested group in place instead of * appending a second top-level group; a top-level match wins over a nested one (#302). * * A group without `groupType` is stored as `'or'`, also when it replaces an existing group * (#362), so setting the same group twice stores the same query. * * @param group - Query group to set * @param options - Optional processing options * @returns Updated query * * @example * ```typescript * list.catalog.query.setGroup({ * groupKey: 'priceRange', * groupType: 'and', * queries: [ * { operator: 'gte', attribute: 'price', value: 50 }, * { operator: 'lte', attribute: 'price', value: 100 } * ] * }); * ``` */ setGroup: (group: DcuplQueryGroup, options?: { skipProcessing?: boolean; }) => DcuplGlobalQueryOptions; /** * Remove query condition(s). * Accepts single condition or array of conditions. * Clearer alias for {@link remove}. * * @param condition - Single query condition or array of conditions to remove * @param options - Optional processing options * @returns Updated query * * @example * ```typescript * // Remove single condition * list.catalog.query.removeCondition({ attribute: 'status', value: 'active' }); * * // Remove multiple conditions * list.catalog.query.removeCondition([ * { attribute: 'status' }, * { attribute: 'price' } * ]); * ``` */ removeCondition: (condition: DcuplQuery | DcuplQuery[], options?: { skipProcessing?: boolean; }) => DcuplGlobalQueryOptions; /** * Remove a query group by its key. * * @param groupKey - Key of the group to remove * @param options - Optional processing options * @returns Updated query * * @example * ```typescript * list.catalog.query.removeGroup('priceRange'); * ``` */ removeGroup: (groupKey: string, options?: { skipProcessing?: boolean; }) => DcuplGlobalQueryOptions; /** * Clear all filters and reset to initial state. * Clearer alias for {@link reset}. * * @param options - Optional processing options * @returns Empty query * * @example * ```typescript * list.catalog.query.clear(); * ``` */ clear: (options?: { skipProcessing?: boolean; }) => DcuplGlobalQueryOptions; /** * Get the current query state. * Clearer alias for {@link get}. * * @returns Current query * * @example * ```typescript * const query = list.catalog.query.current(); * ``` */ current: () => DcuplGlobalQueryOptions; /** * Check if the query has any filter conditions. * * @returns true if query has no conditions, false otherwise * * @example * ```typescript * if (list.catalog.query.isEmpty()) { * console.log('No filters applied'); * } * ``` */ isEmpty: () => boolean; /** * Get all matching items. * Clearer alias for {@link execute} - more intuitive than "all()" which might suggest returning all queries. * * @param options - Optional query options * @returns Array of matching items * * @example * ```typescript * const items = list.catalog.query.items(); * const limited = list.catalog.query.items({ count: 10 }); * const byPrice = list.catalog.query.items({ sort: { attributes: ['price'], order: ['DESC'] } }); * ``` */ items: (query?: DcuplListQueryOptions>) => ItemType[]; /** * Get the first matching result. * * @param options - Optional query options * @returns First matching item or undefined * * @example * ```typescript * const firstItem = list.catalog.query.first(); * const firstActive = list.catalog.query.first({ * queries: [{ operator: 'eq', attribute: 'status', value: 'active' }] * }); * ``` */ first: (query?: DcuplListQueryOptions>) => ItemType | undefined; /** * Check if any results exist for the current query. * * @param options - Optional query options * @returns true if at least one result exists * * @example * ```typescript * if (list.catalog.query.any()) { * console.log('Results found'); * } * * const hasActive = list.catalog.query.any({ * queries: [{ operator: 'eq', attribute: 'status', value: 'active' }] * }); * ``` */ any: (query?: DcuplListQueryOptions>) => boolean; /** * Count matching items for the current query. * * @param options - Optional query options * @returns Number of matching items * * @example * ```typescript * const total = list.catalog.query.count(); * const activeCount = list.catalog.query.count({ * queries: [{ operator: 'eq', attribute: 'status', value: 'active' }] * }); * ``` */ count: (query?: DcuplListQueryOptions>) => number; }; filters: { get: (options: DcuplFilterOptions & { filterKey: string; }) => FilterItem | undefined; getAll: (options?: DcuplFiltersOptions) => FilterItem[]; }; fn: { pivot: (options: PivotOptions) => PivotResponse; aggregate: (options: AggregationOptions) => Aggregation; suggest: (options: SuggestionOptions) => Suggestion[]; groupBy: (options: DcuplGroupByOptions) => GroupByResponse; facets: (options: DcuplFacetOptions) => DcuplFacet[]; metadata: () => ListMetadata; }; private getViews; private _getMetadata; private getFilters; private _getFilters; private getFilter; private _getFilter; private getQuery; private hasGroupOrQueryKey; private applyQuery; /** * Rejects a condition or group the query engine cannot evaluate (e.g. `in` with a non-array * value) BEFORE it is stored (#383). It used to be stored first and then fail while computing * the result, so it stayed in the list's query and every later read of the list threw the same * error. Only what `applyQuery` stores is checked, with the same rules (and messages) as a read. */ private assertValidQueryToApply; private applyOptions; private removeQuery; private resetQuery; private executeQuery; private _getSections; private _getItem; private _getManyItems; private _getSuggestions; private _getFacets; /** * A facet needs `options.attribute`, an attribute of the model (#558): without options the SDK threw * a TypeError, and an unknown attribute answered `[]`. A dotted or bracket path is checked on its * first segment only (a key that contains a dot passes as a whole); the later segments are #191. */ private assertFacetAttribute; private computeFacetsInternal; private getAggregate; private _getPivot; }