UNPKG

@primno/core

Version:

Front-end framework for Model-Driven Apps of Power Apps and Dynamics 365.

30 lines (29 loc) 2.33 kB
/// <reference types="xrm" /> import { ColumnType, FormConfig, FormEventArg, PropertyTypeReplacer, RecursiveNoUndefined } from "../../typing"; type ColumnTypeToXrmAttribute<T extends ColumnType> = T extends ColumnType.boolean ? Xrm.Attributes.BooleanAttribute : T extends ColumnType.string ? Xrm.Attributes.StringAttribute : T extends ColumnType.datetime ? Xrm.Attributes.DateAttribute : T extends ColumnType.lookup ? Xrm.Attributes.LookupAttribute : T extends ColumnType.optionset ? Xrm.Attributes.OptionSetAttribute : T extends ColumnType.number ? Xrm.Attributes.NumberAttribute : Xrm.Attributes.Attribute; type ColumnTypeToXrmControl<T extends ColumnType> = T extends ColumnType.boolean ? Xrm.Controls.OptionSetControl : T extends ColumnType.string ? Xrm.Controls.StringControl : T extends ColumnType.datetime ? Xrm.Controls.DateControl : T extends ColumnType.lookup ? Xrm.Controls.LookupControl : T extends ColumnType.optionset ? Xrm.Controls.OptionSetControl : T extends ColumnType.number ? Xrm.Controls.NumberControl : Xrm.Controls.Control; type ExtractAttributeTypeValue<T extends Xrm.Attributes.Attribute> = ReturnType<T["getValue"]>; type ColumnTypeMetadata = Record<string, ColumnType>; type Columns<T extends ColumnTypeMetadata> = { [P in keyof T]: ColumnTypeToXrmAttribute<T[P]>; }; type Controls<T extends ColumnTypeMetadata> = { [P in keyof T]: ColumnTypeToXrmControl<T[P]>; }; type Values<T extends ColumnTypeMetadata> = { [P in keyof T]: ExtractAttributeTypeValue<ColumnTypeToXrmAttribute<T[P]>>; }; type Tabs<TConfig extends FormConfig> = { [P in keyof TConfig['tabs']]: Xrm.Controls.Tab; }; export type ColumnTypeReplacer<TColumns extends Record<string, unknown>> = PropertyTypeReplacer<TColumns, ColumnType>; export type ColumnsMetadataFromConfig<TConfig extends FormConfig> = ColumnTypeReplacer<RecursiveNoUndefined<TConfig["columns"]>>; /** Provides the tools allowing direct access to the columns, controls, values and tab of the form from the configuration */ export declare class XrmMapper<TConfig extends FormConfig, TColumnMetaData extends ColumnsMetadataFromConfig<TConfig>> { constructor(eventArg: FormEventArg, config: TConfig); columns: Columns<TColumnMetaData>; controls: Controls<TColumnMetaData>; values: Values<TColumnMetaData>; tabs: Tabs<TConfig>; } export {};