@itwin/presentation-backend
Version:
Backend of iTwin.js Presentation library
398 lines • 19.7 kB
TypeScript
/** @packageDocumentation
* @module Core
*/
import { IModelDb } from "@itwin/core-backend";
import { BeEvent } from "@itwin/core-bentley";
import { FormatsProvider, UnitSystemKey } from "@itwin/core-quantity";
import { SchemaContext } from "@itwin/ecschema-metadata";
import { UnitSystemFormat as CommonUnitSystemFormat, ComputeSelectionRequestOptions, Content, ContentDescriptorRequestOptions, ContentRequestOptions, ContentSourcesRequestOptions, Descriptor, DescriptorOverrides, DisplayLabelRequestOptions, DisplayLabelsRequestOptions, DisplayValueGroup, DistinctValuesRequestOptions, ElementProperties, FilterByInstancePathsHierarchyRequestOptions, FilterByTextHierarchyRequestOptions, FormatsMap, HierarchyCompareInfo, HierarchyCompareOptions, HierarchyLevelDescriptorRequestOptions, HierarchyRequestOptions, InstanceKey, Item, KeySet, LabelDefinition, MultiElementPropertiesRequestOptions, Node, NodeKey, NodePathElement, Paged, PagedResponse, Prioritized, Ruleset, RulesetVariable, SelectClassInfo, SelectionScope, SelectionScopeRequestOptions, SingleElementPropertiesRequestOptions, WithCancelEvent } from "@itwin/presentation-common";
import { _presentation_manager_detail } from "./InternalSymbols.js";
import { PresentationManagerDetail } from "./PresentationManagerDetail.js";
import { RulesetManager } from "./RulesetManager.js";
import { RulesetVariablesManager } from "./RulesetVariablesManager.js";
import { BackendDiagnosticsAttribute, BackendDiagnosticsOptions } from "./Utils.js";
/**
* Presentation hierarchy cache mode.
* @public
*/
export declare enum HierarchyCacheMode {
/**
* Hierarchy cache is created in memory.
*/
Memory = "memory",
/**
* Hierarchy cache is created on disk. In this mode hierarchy cache is persisted between iModel
* openings.
*/
Disk = "disk",
/**
* Hierarchy cache is created on disk. In this mode everything is cached in memory while creating hierarchy level
* and persisted in disk cache when whole hierarchy level is created.
*
* **Note:** This mode is still experimental.
*/
Hybrid = "hybrid"
}
/**
* Configuration for hierarchy cache.
* @public
*/
export type HierarchyCacheConfig = MemoryHierarchyCacheConfig | DiskHierarchyCacheConfig | HybridCacheConfig;
/**
* Base interface for all [[HierarchyCacheConfig]] implementations.
* @public
*/
export interface HierarchyCacheConfigBase {
mode: HierarchyCacheMode;
}
/**
* Configuration for in-memory hierarchy cache.
*
* @see [Memory cache documentation page]($docs/presentation/advanced/Caching.md#memory-cache)
* @public
*/
export interface MemoryHierarchyCacheConfig extends HierarchyCacheConfigBase {
mode: HierarchyCacheMode.Memory;
}
/**
* Configuration for persistent disk hierarchy cache.
*
* @see [Disk cache documentation page]($docs/presentation/advanced/Caching.md#disk-cache)
* @public
*/
export interface DiskHierarchyCacheConfig extends HierarchyCacheConfigBase {
mode: HierarchyCacheMode.Disk;
/**
* A directory for hierarchy caches. If set, the directory must exist. Relative paths start from `process.cwd()`.
*
* The default directory depends on the iModel and the way it's opened.
*/
directory?: string;
/**
* While the cache itself is stored on a disk, there's still a required small in-memory cache.
* The parameter allows controlling size of that cache. Defaults to `32768000` bytes (32 MB).
*/
memoryCacheSize?: number;
}
/**
* Configuration for the experimental hybrid hierarchy cache.
*
* Hybrid cache uses a combination of in-memory and disk caches, which should make it a better
* alternative for cases when there are lots of simultaneous requests.
*
* @see [Hybrid cache documentation page]($docs/presentation/advanced/Caching.md#hybrid-cache)
* @public
*/
export interface HybridCacheConfig extends HierarchyCacheConfigBase {
mode: HierarchyCacheMode.Hybrid;
/** Configuration for disk cache used to persist hierarchies. */
disk?: DiskHierarchyCacheConfig;
}
/**
* Configuration for content cache.
*
* @see [Content cache documentation page]($docs/presentation/advanced/Caching.md#content-cache)
* @public
*/
export interface ContentCacheConfig {
/**
* Maximum number of content descriptors cached in memory for quicker paged content requests.
*
* Defaults to `100`.
*/
size?: number;
}
/**
* Caching configuration options for [[PresentationManager]].
* @public
*/
export interface PresentationManagerCachingConfig {
/**
* Hierarchies-related caching options.
*
* @see [Hierarchies cache documentation page]($docs/presentation/advanced/Caching.md#hierarchies-cache)
*/
hierarchies?: HierarchyCacheConfig;
/**
* Content-related caching options.
*
* @see [Content cache documentation page]($docs/presentation/advanced/Caching.md#content-cache)
*/
content?: ContentCacheConfig;
/**
* Each worker thread (see [[workerThreadsCount]]) opens a connection to an iModel used for a request. This
* means there could be `{workerThreadsCount} * {iModels count}` number of connections. Each connection
* uses a memory cache to increase iModel read performance. This parameter allows controlling the size of that
* cache. Defaults to `32768000` bytes (32 MB).
*
* @see [Worker connections cache documentation page]($docs/presentation/advanced/Caching.md#worker-connections-cache)
*/
workerConnectionCacheSize?: number;
}
/**
* A data structure that associates unit systems with a format. The associations are used for
* assigning default unit formats for specific phenomenons (see [[PresentationManagerProps.defaultFormats]]).
*
* @public
* @deprecated in 4.3 - will not be removed until after 2026-06-13. The type has been moved to `@itwin/presentation-common` package.
*/
export type UnitSystemFormat = CommonUnitSystemFormat;
/**
* Data structure for multiple element properties request response.
* @public
*/
export interface MultiElementPropertiesResponse<TParsedContent = ElementProperties> {
total: number;
iterator: () => AsyncGenerator<TParsedContent[]>;
}
/**
* Configuration options for supplying asset paths to [[PresentationManager]].
* @public
*/
export interface PresentationAssetsRootConfig {
/**
* Path to `presentation-backend` assets. Relative paths start from `process.cwd()`.
*/
backend: string;
}
/**
* Properties that can be used to configure [[PresentationManager]]
* @public
*/
export interface PresentationManagerProps {
/**
* Path overrides for presentation backend assets. Need to be overriden by application if it puts these assets someplace else than the default.
*
* By default the path to assets directory is determined during the call of [[Presentation.initialize]] using this algorithm:
*
* - if path of `.js` file that contains [[PresentationManager]] definition contains "presentation-backend", assume the package is in `node_modules` and the directory structure is:
* - `assets/*\*\/*`
* - `presentation-backend/{presentation-backend source files}`
*
* which means the assets can be found through a relative path `../assets/` from the JS file being executed.
*
* - else, assume the backend is webpacked into a single file with assets next to it:
* - `assets/*\*\/*`
* - `{source file being executed}.js`
*
* which means the assets can be found through a relative path `./assets/` from the `{source file being executed}`.
*
* @deprecated in 4.2 - will not be removed until after 2026-06-13. This attribute is not used anymore - the package is not using private assets anymore.
*/
presentationAssetsRoot?: string | PresentationAssetsRootConfig;
/**
* A list of directories containing application's presentation rulesets. Relative
* paths start from `process.cwd()`. The directories are traversed recursively.
*
* @note Only files with `.PresentationRuleSet.json` are read.
*/
rulesetDirectories?: string[];
/**
* A list of directories containing application's supplemental presentation rulesets. Relative
* paths start from `process.cwd()`. The directories are traversed recursively.
*
* @note Only files with `.PresentationRuleSet.json` are read.
*/
supplementalRulesetDirectories?: string[];
/**
* Sets the active unit system to use for formatting property values with
* units. Default presentation units are used if this is not specified. The active unit
* system can later be changed through [[PresentationManager.activeUnitSystem]] or overriden for each request
* through request options.
*/
defaultUnitSystem?: UnitSystemKey;
/**
* A map of default unit formats to use for formatting properties that don't have a presentation format
* in requested unit system.
*
* @deprecated in 5.1 - will not be removed until after 2026-08-08. Use `formatsProvider` instead. Still used as a fallback if `formatsProvider` is not supplied.
*/
defaultFormats?: FormatsMap;
/**
* A custom formats provider to use for formatting property values with units. Defaults to [SchemaFormatsProvider]($ecschema-metadata) if
* not supplied.
*/
formatsProvider?: FormatsProvider;
/**
* A number of worker threads to use for handling presentation requests. Defaults to `2`.
*/
workerThreadsCount?: number;
/**
* The interval (in milliseconds) used to poll for presentation data changes. If not set, presentation
* data changes are not tracked at all.
*
* @beta
* @deprecated in 4.4 - will not be removed until after 2026-06-13. The manager now always tracks for iModel data changes without polling.
*/
updatesPollInterval?: number;
/** Options for caching. */
caching?: PresentationManagerCachingConfig;
/**
* Use [SQLite's Memory-Mapped I/O](https://sqlite.org/mmap.html) for worker connections. This mode improves performance of handling
* requests with high I/O intensity, e.g. filtering large tables on non-indexed columns. No downsides have been noticed.
*
* Set to a falsy value to turn off. `true` for memory-mapping the whole iModel. Number value for memory-mapping the specified amount of bytes.
*/
useMmap?: boolean | number;
/**
* Localization function to localize data returned by presentation manager when it's used directly on the backend (as opposed to when used through RPC, where
* data is localized on the frontend). Defaults to English localization.
*
* @see [Localization]($docs/presentation/advanced/Localization)
*/
getLocalizedString?: (key: string) => string;
/**
* Callback that provides [SchemaContext]($ecschema-metadata) for supplied [IModelDb]($core-backend).
* [SchemaContext]($ecschema-metadata) is used for getting metadata required for values formatting.
*
* @deprecated in 5.1 - will not be removed until after 2026-08-08. By default [IModelDb.schemaContext]($core-backend) is now used instead.
*/
schemaContextProvider?: (imodel: IModelDb) => SchemaContext;
/**
* Parameters for gathering diagnostics at the manager level. When supplied, they're used with every request
* made through the manager.
*
* @see [Diagnostics documentation page]($docs/presentation/advanced/Diagnostics.md)
*/
diagnostics?: BackendDiagnosticsOptions;
}
/**
* Backend Presentation manager which pulls the presentation data from
* an iModel using native platform.
*
* @public
*/
export declare class PresentationManager {
private _props;
private _detail;
private _localizationHelper;
private _schemaContextProvider;
/**
* Creates an instance of PresentationManager.
* @param props Optional configuration properties.
*/
constructor(props?: PresentationManagerProps);
/** Get / set active unit system used to format property values with units */
get activeUnitSystem(): UnitSystemKey | undefined;
set activeUnitSystem(value: UnitSystemKey | undefined);
/** Dispose the presentation manager. Must be called to clean up native resources. */
[Symbol.dispose](): void;
/** @deprecated in 5.0 - will not be removed until after 2026-06-13. Use [Symbol.dispose] instead. */
dispose(): void;
/** An event, that this manager raises whenever any request is made on it. */
get onUsed(): BeEvent<() => void>;
/** Properties used to initialize the manager */
get props(): PresentationManagerProps;
/** Get rulesets manager */
rulesets(): RulesetManager;
/**
* Get ruleset variables manager for specific ruleset
* @param rulesetId Id of the ruleset to get variables manager for
*/
vars(rulesetId: string): RulesetVariablesManager;
/** @internal */
get [_presentation_manager_detail](): PresentationManagerDetail;
getRulesetId(rulesetOrId: Ruleset | string): string;
/**
* Retrieves nodes
* @public
*/
getNodes(requestOptions: WithCancelEvent<Prioritized<Paged<HierarchyRequestOptions<IModelDb, NodeKey, RulesetVariable>>>> & BackendDiagnosticsAttribute): Promise<Node[]>;
/**
* Retrieves nodes count
* @public
*/
getNodesCount(requestOptions: WithCancelEvent<Prioritized<HierarchyRequestOptions<IModelDb, NodeKey, RulesetVariable>>> & BackendDiagnosticsAttribute): Promise<number>;
/**
* Retrieves hierarchy level descriptor
* @public
*/
getNodesDescriptor(requestOptions: WithCancelEvent<Prioritized<HierarchyLevelDescriptorRequestOptions<IModelDb, NodeKey, RulesetVariable>>> & BackendDiagnosticsAttribute): Promise<Descriptor | undefined>;
/**
* Retrieves paths from root nodes to children nodes according to specified instance key paths. Intersecting paths will be merged.
* TODO: Return results in pages
* @public
*/
getNodePaths(requestOptions: WithCancelEvent<Prioritized<FilterByInstancePathsHierarchyRequestOptions<IModelDb, RulesetVariable>>> & BackendDiagnosticsAttribute): Promise<NodePathElement[]>;
/**
* Retrieves paths from root nodes to nodes containing filter text in their label.
* TODO: Return results in pages
* @public
*/
getFilteredNodePaths(requestOptions: WithCancelEvent<Prioritized<FilterByTextHierarchyRequestOptions<IModelDb, RulesetVariable>>> & BackendDiagnosticsAttribute): Promise<NodePathElement[]>;
/**
* Get information about the sources of content when building it for specific ECClasses. Sources involve classes of the primary select instance,
* its related instances for loading related and navigation properties.
* @public
*/
getContentSources(requestOptions: WithCancelEvent<Prioritized<ContentSourcesRequestOptions<IModelDb>>> & BackendDiagnosticsAttribute): Promise<SelectClassInfo[]>;
/**
* Retrieves the content descriptor which can be used to get content
* @public
*/
getContentDescriptor(requestOptions: WithCancelEvent<Prioritized<ContentDescriptorRequestOptions<IModelDb, KeySet, RulesetVariable>>> & BackendDiagnosticsAttribute): Promise<Descriptor | undefined>;
/**
* Retrieves the content set size based on the supplied content descriptor override
* @public
*/
getContentSetSize(requestOptions: WithCancelEvent<Prioritized<ContentRequestOptions<IModelDb, Descriptor | DescriptorOverrides, KeySet, RulesetVariable>>> & BackendDiagnosticsAttribute): Promise<number>;
private createContentFormatter;
/**
* Retrieves the content set based on the supplied content descriptor.
* @public
*/
getContentSet(requestOptions: WithCancelEvent<Prioritized<Paged<ContentRequestOptions<IModelDb, Descriptor, KeySet, RulesetVariable>>>> & BackendDiagnosticsAttribute): Promise<Item[]>;
/**
* Retrieves the content based on the supplied content descriptor override.
* @public
*/
getContent(requestOptions: WithCancelEvent<Prioritized<Paged<ContentRequestOptions<IModelDb, Descriptor | DescriptorOverrides, KeySet, RulesetVariable>>>> & BackendDiagnosticsAttribute): Promise<Content | undefined>;
/**
* Retrieves distinct values of specific field from the content based on the supplied content descriptor override.
* @param requestOptions Options for the request
* @return A promise object that returns either distinct values on success or an error string on error.
* @public
*/
getPagedDistinctValues(requestOptions: WithCancelEvent<Prioritized<DistinctValuesRequestOptions<IModelDb, Descriptor | DescriptorOverrides, KeySet, RulesetVariable>>> & BackendDiagnosticsAttribute): Promise<PagedResponse<DisplayValueGroup>>;
/**
* Retrieves property data in a simplified format for a single element specified by ID.
* @public
*/
getElementProperties<TParsedContent = ElementProperties>(requestOptions: WithCancelEvent<Prioritized<SingleElementPropertiesRequestOptions<IModelDb, TParsedContent>>> & BackendDiagnosticsAttribute): Promise<TParsedContent | undefined>;
/**
* Retrieves property data in simplified format for multiple elements specified by class or all element.
* @return An object that contains element count and AsyncGenerator to iterate over properties of those elements in batches of undefined size.
* @public
*/
getElementProperties<TParsedContent = ElementProperties>(requestOptions: WithCancelEvent<Prioritized<MultiElementPropertiesRequestOptions<IModelDb, TParsedContent>>> & BackendDiagnosticsAttribute): Promise<MultiElementPropertiesResponse<TParsedContent>>;
private getSingleElementProperties;
private getMultipleElementProperties;
/**
* Retrieves display label definition of specific item
* @public
*/
getDisplayLabelDefinition(requestOptions: WithCancelEvent<Prioritized<DisplayLabelRequestOptions<IModelDb, InstanceKey>>> & BackendDiagnosticsAttribute): Promise<LabelDefinition>;
/**
* Retrieves display label definitions of specific items
* @public
*/
getDisplayLabelDefinitions(requestOptions: WithCancelEvent<Prioritized<Paged<DisplayLabelsRequestOptions<IModelDb, InstanceKey>>>> & BackendDiagnosticsAttribute): Promise<LabelDefinition[]>;
/**
* Retrieves available selection scopes.
* @public
* @deprecated in 5.0 - will not be removed until after 2026-06-13. Use `computeSelection` from [@itwin/unified-selection](https://github.com/iTwin/presentation/blob/master/packages/unified-selection/README.md#selection-scopes) package instead.
*/
getSelectionScopes(_requestOptions: SelectionScopeRequestOptions<IModelDb> & BackendDiagnosticsAttribute): Promise<SelectionScope[]>;
/**
* Computes selection based on provided element IDs and selection scope.
* @public
* @deprecated in 5.0 - will not be removed until after 2026-06-13. Use `computeSelection` from [@itwin/unified-selection](https://github.com/iTwin/presentation/blob/master/packages/unified-selection/README.md#selection-scopes) package instead.
*/
computeSelection(requestOptions: ComputeSelectionRequestOptions<IModelDb> & BackendDiagnosticsAttribute): Promise<KeySet>;
/**
* Compares two hierarchies specified in the request options
* @public
*/
compareHierarchies(requestOptions: HierarchyCompareOptions<IModelDb, NodeKey>): Promise<HierarchyCompareInfo>;
}
//# sourceMappingURL=PresentationManager.d.ts.map