@itwin/presentation-shared
Version:
The package contains types and utilities used across different iTwin.js Presentation packages.
121 lines • 5.52 kB
TypeScript
import { ECSchemaProvider, PrimitiveValueType } from "../Metadata.js";
import { PrimitiveValue, TypedPrimitiveValue } from "../Values.js";
/**
* Props for selecting a `TypedPrimitiveValue` using given ECSQL selector.
* @public
*/
type TypedPrimitiveValueSelectorProps = {
/** ECSQL selector to query the value */
selector: string;
} & ({
/** Type of the value. Defaults to `String`. */
type?: undefined;
} | {
type: Exclude<PrimitiveValueType, "Double">;
extendedType?: string;
} | {
type: Extract<PrimitiveValueType, "Double">;
extendedType?: string;
koqName?: string;
});
/**
* A union of prop types for selecting a value and its metadata in ECSQL query.
* @public
*/
export type TypedValueSelectClauseProps = TypedPrimitiveValue | TypedPrimitiveValueSelectorProps;
/** @public */
export declare namespace TypedValueSelectClauseProps {
function isPrimitiveValue(props: TypedValueSelectClauseProps): props is TypedPrimitiveValue;
function isPrimitiveValueSelector(props: TypedValueSelectClauseProps): props is TypedPrimitiveValueSelectorProps;
}
/**
* A function for a creating a `TypedPrimitiveValueSelectorProps` object from given primitive ECProperty information.
* @throws Error if the property is not found, is not primitive or has unsupported primitive type (Binary, IGeometry).
* @public
*/
export declare function createPrimitivePropertyValueSelectorProps({ schemaProvider, propertyClassAlias, propertyClassName, propertyName, }: {
/** Access to schema information. */
schemaProvider: ECSchemaProvider;
/** Full class name of the property. Format: `SchemaName.ClassName`. */
propertyClassName: string;
/** Query alias of the class that contains the property. */
propertyClassAlias: string;
/** Name of the property to create `TypedPrimitiveValue` for. */
propertyName: string;
}): Promise<TypedPrimitiveValueSelectorProps>;
/**
* Creates an ECSQL selector for raw property value, or, optionally - it's component. Example result:
* `[classAlias].[propertyName].[componentName]`.
*
* @public
*/
export declare function createRawPropertyValueSelector(classAlias: string, propertyName: string, componentName?: string): string;
/**
* Creates an ECSQL selector for a raw primitive value.
* - `undefined` is selected as `NULL`.
* - `Date` values are selected in julian day format.
* - `Point2d` and `Point3d` values are selected as serialized JSON objects, e.g. `{ x: 1, y: 2, z: 3 }`.
* - Other kinds of values are selected as-is.
*
* @public
*/
export declare function createRawPrimitiveValueSelector(value: PrimitiveValue | undefined): string;
/**
* Creates an ECSQL selector that results in a stringified `InstanceKey` object.
* @public
*/
export declare function createInstanceKeySelector(props: {
alias: string;
}): string;
/**
* Creates a clause for returning `NULL` when `checkSelector` returns a falsy value, or result of `valueSelector`
* otherwise. Example result: `IIF(CHECK_SELECTOR, VALUE_SELECTOR, NULL)`.
*
* @note In SQL `NULL` is not considered falsy, so when checking for `NULL` values, the `checkSelector` should
* be like `{selector} IS NOT NULL` rather than just `${selector}`.
*
* @public
*/
export declare function createNullableSelector(props: {
checkSelector: string;
valueSelector: string;
}): string;
/**
* Create an ECSQL selector combined of multiple typed value selectors in a form of a JSON array. This allows handling results
* of each value selector individually when parsing query result.
*
* Example result: `json_array(VALUE_SELECTOR_1, VALUE_SELECTOR_2, ...)`.
*
* Optionally, the function also accepts a `checkSelector` argument, which can be used to make the selector return
* `NULL` result when the argument selector results in `NULL`. Example result with `checkSelector`:
* `IIF(CHECK_SELECTOR, json_array(VALUE_SELECTOR_1, VALUE_SELECTOR_2, ...), NULL)`.
*
* @note The resulting JSON is of `ConcatenatedValue` type and it's recommended to use `ConcatenatedValue.serialize` to
* handle each individual part.
*
* @see `ConcatenatedValue`
*
* @public
*/
export declare function createConcatenatedValueJsonSelector(selectors: TypedValueSelectClauseProps[], checkSelector?: string): string;
/**
* Create an ECSQL selector combined of multiple typed value selectors in a form of a string.
*
* Example result: `VALUE_SELECTOR_1 || VALUE_SELECTOR_2 || ...`.
*
* Optionally, the function also accepts a `checkSelector` argument, which can be used to make the selector return
* `NULL` result when `checkSelector` results in a falsy value. Example result with `checkSelector`:
* `IIF(CHECK_SELECTOR, VALUE_SELECTOR_1 || VALUE_SELECTOR_2 || ..., NULL)`.
*
* @note Not all types of `TypedValueSelectClauseProps` can be serialized to a user-friendly string, e.g. when
* selecting a numeric value with units, this function is going to select the raw value. To create properly formatted
* concatenated values:
* 1. They should be selected with `createConcatenatedValueJsonSelector`, which returns a serialized JSON object.
* 2. The JSON should be parsed from resulting string and passed to `ConcatenatedValue.serialize`, which additionally
* takes a formatter. One can be created using `createDefaultValueFormatter`.
*
* @public
*/
export declare function createConcatenatedValueStringSelector(selectors: TypedValueSelectClauseProps[], checkSelector?: string): string;
export {};
//# sourceMappingURL=ECSqlValueSelectorSnippets.d.ts.map