@infomaximum/widget-sdk 7.0.0-16 → 7.0.0-18

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -2,6 +2,22 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
4
4
 
5
+ ## [7.0.0-18](https://github.com/Infomaximum/widget-sdk/compare/v7.0.0-17...v7.0.0-18) (2026-04-20)
6
+
7
+
8
+ ### Features
9
+
10
+ * внедрены extendWithMeta и omitWithMeta в схемы ([5f9cddd](https://github.com/Infomaximum/widget-sdk/commit/5f9cdddec5a78b38a61f831fde705741a03da243))
11
+ * добавлены утилиты для работы с мета-цепочкой Zod-схем ([949b27d](https://github.com/Infomaximum/widget-sdk/commit/949b27d1e8822976d051caa361c766bceabd7d67))
12
+
13
+ ## [7.0.0-17](https://github.com/Infomaximum/widget-sdk/compare/v7.0.0-16...v7.0.0-17) (2026-04-15)
14
+
15
+
16
+ ### Features
17
+
18
+ * добавлена вспомогательная функция mapValues (для внутреннего использования) ([9f4beb0](https://github.com/Infomaximum/widget-sdk/commit/9f4beb0c86e81fdc763046425d749168b7deaae4))
19
+ * добавлено кеширование результатов вызова фабрик схем ([e116856](https://github.com/Infomaximum/widget-sdk/commit/e1168567088fd02e6557abfc6d5c179194eb430c))
20
+
5
21
  ## [7.0.0-16](https://github.com/Infomaximum/widget-sdk/compare/v7.0.0-15...v7.0.0-16) (2026-04-08)
6
22
 
7
23
 
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import * as zod from 'zod';
2
- import { ZodType, z } from 'zod';
2
+ import { ZodType, z, ZodObject } from 'zod';
3
3
  import * as zod_v4_core from 'zod/v4/core';
4
4
  import * as _infomaximum_bi_formatting from '@infomaximum/bi-formatting';
5
5
  import { EFormatTypes, EFormattingPresets } from '@infomaximum/bi-formatting';
@@ -63,6 +63,16 @@ declare class VersionedSchemaFactory {
63
63
  private static findClosestVersion;
64
64
  /** Добавляет метаданные к схеме (curried) */
65
65
  private static annotateSchema;
66
+ /**
67
+ * Оборачивает фабрику схемы, добавляя кеширование результата.
68
+ *
69
+ * Предполагается, что `z` — синглтон (один экземпляр на всё приложение),
70
+ * поэтому достаточно закешировать единственный результат.
71
+ *
72
+ * Вызовы с дополнительными аргументами (restArgs) не кешируются,
73
+ * так как результат может зависеть от их значений.
74
+ */
75
+ private static withCache;
66
76
  /** Построить версионированную схему */
67
77
  static build<THistory extends Record<string, ISchemaFactory>, TLatestVersion extends keyof THistory>({ history, latestVersion, meta, }: IVersionedSchemaBuildParams<THistory, TLatestVersion>): TVersionedSchema<THistory, TLatestVersion>;
68
78
  }
@@ -19727,6 +19737,63 @@ interface ITheme {
19727
19737
  */
19728
19738
  declare const themed: <Value, Theme = ITheme>(scheme: ZodType<Value>, selectThemeValue: (theme: Theme) => Value) => ZodType<Value, unknown, zod_v4_core.$ZodTypeInternals<Value, unknown>>;
19729
19739
 
19740
+ /**
19741
+ * Возвращает родительскую мету схемы, установленную через extendWithMeta / omitWithMeta.
19742
+ * Используй для обхода цепочки наследования схем.
19743
+ */
19744
+ declare function getParentMeta(meta: Record<string, unknown>): Record<string, unknown> | undefined;
19745
+ /**
19746
+ * Расширяет Zod-схему дополнительными полями, сохраняя цепочку наследования мет.
19747
+ *
19748
+ * Мета базовой схемы сохраняется как `parent` в мете расширенной схемы — формируя
19749
+ * иммутабельный связанный список.
19750
+ *
19751
+ * Используй вместо `.extend()` при расширении схем, задекларированных через
19752
+ * `SchemaRegistry.define`, — это обязательное условие корректной работы миграций.
19753
+ *
19754
+ * @example
19755
+ * // Вместо:
19756
+ * DimensionSchema(z).extend({ color: ColorSchema(z) })
19757
+ *
19758
+ * // Используй:
19759
+ * extendWithMeta(DimensionSchema(z), { color: ColorSchema(z) })
19760
+ */
19761
+ declare function extendWithMeta<TShape extends Record<string, any>, TConfig extends {
19762
+ out: Record<string, any>;
19763
+ in: Record<string, any>;
19764
+ }, U extends Record<string, any>>(schema: ZodObject<TShape, TConfig>, extension: U): ZodObject<(keyof TShape & keyof U extends never ? TShape & U : { [K in keyof TShape as K extends keyof U ? never : K]: TShape[K]; } & { [K_1 in keyof U]: U[K_1]; }) extends infer T ? { [k in keyof T]: (keyof TShape & keyof U extends never ? TShape & U : { [K in keyof TShape as K extends keyof U ? never : K]: TShape[K]; } & { [K_1 in keyof U]: U[K_1]; })[k]; } : never, TConfig>;
19765
+ /**
19766
+ * Создаёт Zod-схему с удалёнными полями, сохраняя цепочку наследования мет.
19767
+ *
19768
+ * Мета базовой схемы сохраняется как `parent` в мете результирующей схемы.
19769
+ *
19770
+ * Используй вместо `.omit()` при работе со схемами, задекларированными через
19771
+ * `SchemaRegistry.define`, — это обязательное условие корректной работы миграций.
19772
+ *
19773
+ * @example
19774
+ * // Вместо:
19775
+ * BaseWidgetSettingsSchema(z).omit({ paddings: true })
19776
+ *
19777
+ * // Используй:
19778
+ * omitWithMeta(BaseWidgetSettingsSchema(z), { paddings: true })
19779
+ */
19780
+ declare function omitWithMeta<TShape extends Record<string, any>, TConfig extends {
19781
+ out: Record<string, any>;
19782
+ in: Record<string, any>;
19783
+ }, M extends {
19784
+ [k in keyof TShape]?: true;
19785
+ }>(schema: ZodObject<TShape, TConfig>, keys: M): ZodObject<Omit<TShape, Extract<keyof TShape, keyof M>> extends infer T ? { [k in keyof T]: Omit<TShape, Extract<keyof TShape, keyof M>>[k]; } : never, TConfig>;
19786
+ /**
19787
+ * Проверяет, есть ли в цепочке наследования мет узел, удовлетворяющий предикату.
19788
+ *
19789
+ * Обходит цепочку от текущей меты к корню через ссылки parent, установленные
19790
+ * функциями extendWithMeta / omitWithMeta.
19791
+ *
19792
+ * @example
19793
+ * hasInMetaChain(schema.meta(), (meta) => meta.type === "WidgetDimension")
19794
+ */
19795
+ declare function hasInMetaChain(meta: Record<string, unknown> | undefined, predicate: (meta: Record<string, unknown>) => boolean): boolean;
19796
+
19730
19797
  /**
19731
19798
  * Глобальный реестр версионированных схем (публичный слой, только чтение).
19732
19799
  *
@@ -19761,4 +19828,4 @@ declare global {
19761
19828
  }
19762
19829
  }
19763
19830
 
19764
- export { ActionButtonSchema, ActionDrillDownSchema, ActionGoToURLSchema, ActionOnClickParameterSchema, ActionOpenInSchema, ActionOpenViewSchema, ActionRunScriptSchema, ActionSchema, ActionUpdateVariableSchema, ActionsOnClickSchema, AutoIdentifiedArrayItemSchema, BaseWidgetSettingsSchema, ColorAutoSchema, ColorBaseSchema, ColorByDimensionSchema, ColorDisabledSchema, ColorFormulaSchema, ColorGradientSchema, ColorRuleSchema, ColorSchema, ColorValuesSchema, ColoredValueSchema, ColumnIndicatorValueSchema, DimensionProcessFilterSchema, DimensionValueSchema, DisplayConditionSchema, EActionButtonsTypes, EActionTypes, EActivateConditionMode, EAutoUpdateMode, ECalculatorFilterMethods, EClickHouseBaseTypes, EColorMode, EControlType, ECustomSelectTemplates, EDataModelOption, EDimensionAggregationTemplateName, EDimensionProcessFilterTimeUnit, EDimensionTemplateNames, EDisplayConditionMode, EDrawerPlacement, EDurationTemplateName, EDurationUnit, EEventAppearances, EEventMeasureTemplateNames, EFontWeight, EFormatOrFormattingMode, EFormulaFilterFieldKeys, EHeightMode, EIndicatorType, ELastTimeUnit, EMarkdownDisplayMode, EMeasureAggregationTemplateName, EMeasureInnerTemplateNames, EMeasureTemplateNames, EOuterAggregation, EProcessFilterNames, ESelectOptionTypes, ESettingsSchemaMetaKey, ESimpleDataType, ESimpleInputType, ESortDirection, ESortingValueModes, ESystemRecordKey, ETransitionMeasureTemplateNames, EUnitMode, EViewMode, EViewOpenIn, EWidgetActionInputMethod, EWidgetFilterMode, EWidgetIndicatorType, EWidgetIndicatorValueModes, ExtendedFormulaFilterValueSchema, FormatSchema, FormattingSchema, FormulaFilterValueSchema, FormulaNullableSchema, FormulaSchema, type IActionButton, type IActionDrillDown, type IActionGoToUrl, type IActionOnClickControl, type IActionRunScript, type IActionScript, type IActionUpdateVariable, type IAddButtonSelectOption, type IAddDurationOfTransitionFilter, type IAddPresenceOfEventFilter, type IAddPresenceOfTransitionFilter, type IAddRepetitionOfEventFilter, type IAutoIdentifiedArrayItem, type IBaseDimensionsAndMeasuresCalculator, type IBaseDimensionsAndMeasuresCalculatorInput, type IBaseDimensionsAndMeasuresCalculatorOutput, type IBaseWidgetSettings, type ICalculator, type ICalculatorDimensionInput, type ICalculatorDimensionOutput, type ICalculatorFactory, type ICalculatorFilter, type ICalculatorIndicatorInput, type ICalculatorIndicatorOutput, type ICalculatorMeasureInput, type ICalculatorMeasureOutput, type ICalculatorOptions, type ICollapseRecord, type IColorPickerControl, type IColoredValue, type ICommonDimensions, type ICommonMeasures, type ICommonState, type IControlProps, type IControlRecord, type ICustomAddButtonProps, type ICustomWidgetProps, type IDefinition, type IDimensionAddButtonProps, type IDimensionProcessFilter, type IDimensionSelection, type IDimensionSelectionByFormula, type IDisplayConditionControl, type IDisplayPredicate, type IDisplayRule, type IDivePanelDescription, type IDividerRecord, type IEdge, type IEventsColorControl, type IEventsPickerControl, type IExportColumnOrder, type IFillSettings, type IFilterControl, type IFormattingControl, type IFormattingTemplateControl, type IFormulaControl, type IFormulaFilterValue, type IGeneralCalculator, type IGeneralCalculatorExportInput, type IGeneralCalculatorInput, type IGeneralCalculatorOutput, type IGlobalContext, type IGradient, type IGraphElement, type IGroupSetDescription, type IGroupSetRecord, type IGroupSettings, type IHistogramBin, type IHistogramCalculator, type IHistogramCalculatorInput, type IHistogramCalculatorOutput, type IHistoricalSchemaDefinition, type IIndicatorLink, type IInitialSettings, type IInputControl, type IInputMarkdownControl, type IInputNumberControl, type IInputRangeControl, type IInputTemplatedControl, type ILens, type ILifecycleRuntime, type ILifecycleRuntimeFactory, type IMarkdownMeasure, type IMeasureAddButtonProps, type IMigrateContext, type IPanelDescription, type IPanelDescriptionCreator, type IParameterFromAggregation, type IParameterFromColumn, type IParameterFromDynamicList, type IParameterFromEndEvent, type IParameterFromEvent, type IParameterFromFormula, type IParameterFromManualInput, type IParameterFromStartEvent, type IParameterFromStaticList, type IParameterFromVariable, type IPieCalculator, type IPieCalculatorInput, type IPieCalculatorOutput, type IProcessEventFilterValue, type IProcessEventIndicator, type IProcessFilterPreviewParams, type IProcessGraphCalculator, type IProcessGraphCalculatorInput, type IProcessGraphCalculatorOutput, type IProcessIndicator, type IProcessTransitionFilterValue, type IProcessTransitionIndicator, type IRadioIconGroupControl, type IRange, type ISchemaContext, type ISchemaFactory, type ISelectBranchOption, type ISelectControl, type ISelectDividerOption, type ISelectGroupOption, type ISelectLeafOption, type ISelectNode, type ISelectOption, type ISelectSystemOption, type ISizeControl, type ISortOrder, type ISortingAddButtonProps, type IStagesFilterValue, type IStaticListLabeledOption, type ISwitchControl, type ITagSetControl, type ITheme, type ITwoLimitsCalculator, type ITwoLimitsCalculatorExportInput, type ITwoLimitsCalculatorInput, type ITwoLimitsCalculatorOutput, type ITypeCalculator, type ITypeCalculatorInput, type ITypeCalculatorOutput, type ITypeCalculatorOutputItem, type ITypedFormulaControl, type IVertex, type IViewAction, type IViewContext, type IWidget, type IWidgetAction, type IWidgetColumnIndicator, type IWidgetColumnListVariable, type IWidgetDimension, type IWidgetDimensionHierarchy, type IWidgetDimensionInHierarchy, type IWidgetDynamicListVariable, type IWidgetEntity, type IWidgetFilter, type IWidgetFiltration, type IWidgetFormatting, type IWidgetIndicator, type IWidgetIndicatorAddButtonProps, type IWidgetManifest, type IWidgetMeasure, type IWidgetMigrator, type IWidgetPersistValue, type IWidgetPlaceholderController, type IWidgetPlaceholderValues, type IWidgetProcess, type IWidgetProps, type IWidgetSortingIndicator, type IWidgetStaticListVariable, type IWidgetStaticVariable, type IWidgetStruct, type IWidgetTable, type IWidgetTableColumn, KeyNullableSchema, MarkdownMeasureSchema, MeasureValueSchema, NameNullableSchema, OuterAggregation, ParameterFromAggregationSchema, ParameterFromColumnSchema, ParameterFromDataModelSchema, ParameterFromDynamicListSchema, ParameterFromEndEventSchema, ParameterFromEventSchema, ParameterFromFormulaSchema, ParameterFromManualInputSchema, ParameterFromStartEventSchema, ParameterFromStaticListSchema, ParameterFromVariableSchema, ProcessIndicatorSchema, ProcessIndicatorValueSchema, RangeSchema, SchemaRegistryReader, SettingsFilterSchema, SortDirectionSchema, SortOrderSchema, type TAction, type TActionOnClickParameter, type TActionOpenView, type TActionValidator, type TActionsConfig, type TActionsOnClick, type TAddButton, type TAddButtonProps, type TApiVersion, type TBoundedContentWithIndicator, type TColor, type TColorBase, type TColorRule, type TColumnIndicatorValue, type TConditionalDimensionInHierarchy, type TContextMenu, type TContextMenuButton, type TContextMenuButtonActions, type TContextMenuButtonApply, type TContextMenuButtonClose, type TContextMenuButtonCustom, type TContextMenuButtonGroup, type TContextMenuButtonOptions, type TContextMenuList, type TContextMenuPositionUnit, type TContextMenuRow, type TControlUnion, type TControlsSpecMap, type TCustomAddButtonSelectOption, type TCustomControlFactories, type TDefineWidgetOptions, type TDisplayCondition, type TDisplayMode, type TEmptyRecord, type TExtendedFormulaFilterValue, type TFiltrationAccessibility, type TGradientsSetValue, type TGroupLevelRecord, type THSLTuple, type THintPlacement, type TLaunchActionParams, type TLimitedColor, type TMeasureAddButtonSelectOption, type TMigrateProcessor, type TMigrationStruct, type TParameterFromDataModel, type TProcessIndicatorValue, type TRGBTuple, type TRecordAccessor, type TSchemaType, type TSelectChildOptions, type TSelectFetchNodes, type TSelectivePartial, type TSettingsFilter, type TSettingsOf, type TSortDirection, type TTabsHorizontalAlignment, type TUpdateSelection, type TValuePath, type TVersion, type TViewActionParameter, type TWidgetActionParameter, type TWidgetContainer, type TWidgetDimensionData, type TWidgetDimensionUnion, type TWidgetFilterValue, type TWidgetFiltering, type TWidgetIndicatorAggregationValue, type TWidgetIndicatorConversionValue, type TWidgetIndicatorDurationValue, type TWidgetIndicatorTimeValue, type TWidgetLevelRecord, type TWidgetMeasureData, type TWidgetSortingValue, type TWidgetVariable, type TWidgetsPaletteValue, type TZod, VersionedSchemaFactory, ViewActionParameterSchema, ViewActionSchema, WidgetActionParameterSchema, WidgetActionSchema, WidgetColumnIndicatorSchema, WidgetDimensionHierarchySchema, WidgetDimensionInHierarchySchema, WidgetDimensionSchema, WidgetIndicatorAggregationValueSchema, WidgetIndicatorConversionValueSchema, WidgetIndicatorDurationValueSchema, WidgetIndicatorFormulaValueSchema, WidgetIndicatorSchema, WidgetIndicatorTemplateValueSchema, WidgetIndicatorTimeValueSchema, WidgetMeasureAggregationValueSchema, WidgetMeasureSchema, WidgetPresetSettingsSchema, WidgetSortingIndicatorSchema, WidgetSortingValueSchema, apiVersion, apiVersions, applyIndexToArrayFormula, availableFormatsBySimpleType, bindContentWithIndicator, bindContentsWithIndicators, checkDisplayCondition, clearMultiLineComments, clearSingleLineComments, colors, conversionTemplate, convertFiltersToFormula, convertToFormulasChain, countExecutionsTemplate, createEscaper, createAggregationTemplate as createMeasureAggregationTemplate, curlyBracketsContentPattern, dashboardLinkRegExp, defaultActionsConfig, dimensionAggregationTemplates, dimensionTemplateFormulas, displayConditionTemplate, doubleQuoteContentPattern, durationTemplates, escapeCurlyBracketLinkName, escapeDoubleQuoteLinkName, eventMeasureTemplateFormulas, fillTemplateSql, formulaFilterMethods, generateColumnFormula, getColorByIndex, getDefaultSortOrders, getDimensionFormula, getDisplayConditionFormula, getEventMeasureFormula, getMeasureFormula, getProcessDimensionValueFormula, getRuleColor, getTransitionMeasureFormula, hexToRgb, inheritDisplayConditionFromHierarchy, interpolateHexColor, isDimensionProcessFilter, isDimensionsHierarchy, isFormulaFilterValue, isValidColor, mapDimensionsToInputs, mapEventMeasuresToInputs, mapFormulaFilterToCalculatorInput, mapFormulaFiltersToInputs, mapMeasuresToInputs, mapSettingsFiltersToInputs, mapSortingToInputs, mapTransitionMeasuresToInputs, measureInnerTemplateFormulas, measureTemplateFormulas, parseClickHouseType, parseIndicatorLink, prepareConversionParams, prepareDimensionAggregationParams, prepareDurationParams, prepareFormulaForSql, prepareMeasureAggregationParams, prepareSortOrders, prepareTimeParams, prepareValuesForSql, replaceDisplayCondition, replaceFiltersBySelection, replaceHierarchiesWithDimensions, selectDimensionFromHierarchy, themed, timeTemplates, transitionMeasureTemplateFormulas, unescapeSpecialCharacters, updateDefaultModeSelection, updateSingleModeSelection, workspaceLinkRegExp };
19831
+ export { ActionButtonSchema, ActionDrillDownSchema, ActionGoToURLSchema, ActionOnClickParameterSchema, ActionOpenInSchema, ActionOpenViewSchema, ActionRunScriptSchema, ActionSchema, ActionUpdateVariableSchema, ActionsOnClickSchema, AutoIdentifiedArrayItemSchema, BaseWidgetSettingsSchema, ColorAutoSchema, ColorBaseSchema, ColorByDimensionSchema, ColorDisabledSchema, ColorFormulaSchema, ColorGradientSchema, ColorRuleSchema, ColorSchema, ColorValuesSchema, ColoredValueSchema, ColumnIndicatorValueSchema, DimensionProcessFilterSchema, DimensionValueSchema, DisplayConditionSchema, EActionButtonsTypes, EActionTypes, EActivateConditionMode, EAutoUpdateMode, ECalculatorFilterMethods, EClickHouseBaseTypes, EColorMode, EControlType, ECustomSelectTemplates, EDataModelOption, EDimensionAggregationTemplateName, EDimensionProcessFilterTimeUnit, EDimensionTemplateNames, EDisplayConditionMode, EDrawerPlacement, EDurationTemplateName, EDurationUnit, EEventAppearances, EEventMeasureTemplateNames, EFontWeight, EFormatOrFormattingMode, EFormulaFilterFieldKeys, EHeightMode, EIndicatorType, ELastTimeUnit, EMarkdownDisplayMode, EMeasureAggregationTemplateName, EMeasureInnerTemplateNames, EMeasureTemplateNames, EOuterAggregation, EProcessFilterNames, ESelectOptionTypes, ESettingsSchemaMetaKey, ESimpleDataType, ESimpleInputType, ESortDirection, ESortingValueModes, ESystemRecordKey, ETransitionMeasureTemplateNames, EUnitMode, EViewMode, EViewOpenIn, EWidgetActionInputMethod, EWidgetFilterMode, EWidgetIndicatorType, EWidgetIndicatorValueModes, ExtendedFormulaFilterValueSchema, FormatSchema, FormattingSchema, FormulaFilterValueSchema, FormulaNullableSchema, FormulaSchema, type IActionButton, type IActionDrillDown, type IActionGoToUrl, type IActionOnClickControl, type IActionRunScript, type IActionScript, type IActionUpdateVariable, type IAddButtonSelectOption, type IAddDurationOfTransitionFilter, type IAddPresenceOfEventFilter, type IAddPresenceOfTransitionFilter, type IAddRepetitionOfEventFilter, type IAutoIdentifiedArrayItem, type IBaseDimensionsAndMeasuresCalculator, type IBaseDimensionsAndMeasuresCalculatorInput, type IBaseDimensionsAndMeasuresCalculatorOutput, type IBaseWidgetSettings, type ICalculator, type ICalculatorDimensionInput, type ICalculatorDimensionOutput, type ICalculatorFactory, type ICalculatorFilter, type ICalculatorIndicatorInput, type ICalculatorIndicatorOutput, type ICalculatorMeasureInput, type ICalculatorMeasureOutput, type ICalculatorOptions, type ICollapseRecord, type IColorPickerControl, type IColoredValue, type ICommonDimensions, type ICommonMeasures, type ICommonState, type IControlProps, type IControlRecord, type ICustomAddButtonProps, type ICustomWidgetProps, type IDefinition, type IDimensionAddButtonProps, type IDimensionProcessFilter, type IDimensionSelection, type IDimensionSelectionByFormula, type IDisplayConditionControl, type IDisplayPredicate, type IDisplayRule, type IDivePanelDescription, type IDividerRecord, type IEdge, type IEventsColorControl, type IEventsPickerControl, type IExportColumnOrder, type IFillSettings, type IFilterControl, type IFormattingControl, type IFormattingTemplateControl, type IFormulaControl, type IFormulaFilterValue, type IGeneralCalculator, type IGeneralCalculatorExportInput, type IGeneralCalculatorInput, type IGeneralCalculatorOutput, type IGlobalContext, type IGradient, type IGraphElement, type IGroupSetDescription, type IGroupSetRecord, type IGroupSettings, type IHistogramBin, type IHistogramCalculator, type IHistogramCalculatorInput, type IHistogramCalculatorOutput, type IHistoricalSchemaDefinition, type IIndicatorLink, type IInitialSettings, type IInputControl, type IInputMarkdownControl, type IInputNumberControl, type IInputRangeControl, type IInputTemplatedControl, type ILens, type ILifecycleRuntime, type ILifecycleRuntimeFactory, type IMarkdownMeasure, type IMeasureAddButtonProps, type IMigrateContext, type IPanelDescription, type IPanelDescriptionCreator, type IParameterFromAggregation, type IParameterFromColumn, type IParameterFromDynamicList, type IParameterFromEndEvent, type IParameterFromEvent, type IParameterFromFormula, type IParameterFromManualInput, type IParameterFromStartEvent, type IParameterFromStaticList, type IParameterFromVariable, type IPieCalculator, type IPieCalculatorInput, type IPieCalculatorOutput, type IProcessEventFilterValue, type IProcessEventIndicator, type IProcessFilterPreviewParams, type IProcessGraphCalculator, type IProcessGraphCalculatorInput, type IProcessGraphCalculatorOutput, type IProcessIndicator, type IProcessTransitionFilterValue, type IProcessTransitionIndicator, type IRadioIconGroupControl, type IRange, type ISchemaContext, type ISchemaFactory, type ISelectBranchOption, type ISelectControl, type ISelectDividerOption, type ISelectGroupOption, type ISelectLeafOption, type ISelectNode, type ISelectOption, type ISelectSystemOption, type ISizeControl, type ISortOrder, type ISortingAddButtonProps, type IStagesFilterValue, type IStaticListLabeledOption, type ISwitchControl, type ITagSetControl, type ITheme, type ITwoLimitsCalculator, type ITwoLimitsCalculatorExportInput, type ITwoLimitsCalculatorInput, type ITwoLimitsCalculatorOutput, type ITypeCalculator, type ITypeCalculatorInput, type ITypeCalculatorOutput, type ITypeCalculatorOutputItem, type ITypedFormulaControl, type IVertex, type IViewAction, type IViewContext, type IWidget, type IWidgetAction, type IWidgetColumnIndicator, type IWidgetColumnListVariable, type IWidgetDimension, type IWidgetDimensionHierarchy, type IWidgetDimensionInHierarchy, type IWidgetDynamicListVariable, type IWidgetEntity, type IWidgetFilter, type IWidgetFiltration, type IWidgetFormatting, type IWidgetIndicator, type IWidgetIndicatorAddButtonProps, type IWidgetManifest, type IWidgetMeasure, type IWidgetMigrator, type IWidgetPersistValue, type IWidgetPlaceholderController, type IWidgetPlaceholderValues, type IWidgetProcess, type IWidgetProps, type IWidgetSortingIndicator, type IWidgetStaticListVariable, type IWidgetStaticVariable, type IWidgetStruct, type IWidgetTable, type IWidgetTableColumn, KeyNullableSchema, MarkdownMeasureSchema, MeasureValueSchema, NameNullableSchema, OuterAggregation, ParameterFromAggregationSchema, ParameterFromColumnSchema, ParameterFromDataModelSchema, ParameterFromDynamicListSchema, ParameterFromEndEventSchema, ParameterFromEventSchema, ParameterFromFormulaSchema, ParameterFromManualInputSchema, ParameterFromStartEventSchema, ParameterFromStaticListSchema, ParameterFromVariableSchema, ProcessIndicatorSchema, ProcessIndicatorValueSchema, RangeSchema, SchemaRegistryReader, SettingsFilterSchema, SortDirectionSchema, SortOrderSchema, type TAction, type TActionOnClickParameter, type TActionOpenView, type TActionValidator, type TActionsConfig, type TActionsOnClick, type TAddButton, type TAddButtonProps, type TApiVersion, type TBoundedContentWithIndicator, type TColor, type TColorBase, type TColorRule, type TColumnIndicatorValue, type TConditionalDimensionInHierarchy, type TContextMenu, type TContextMenuButton, type TContextMenuButtonActions, type TContextMenuButtonApply, type TContextMenuButtonClose, type TContextMenuButtonCustom, type TContextMenuButtonGroup, type TContextMenuButtonOptions, type TContextMenuList, type TContextMenuPositionUnit, type TContextMenuRow, type TControlUnion, type TControlsSpecMap, type TCustomAddButtonSelectOption, type TCustomControlFactories, type TDefineWidgetOptions, type TDisplayCondition, type TDisplayMode, type TEmptyRecord, type TExtendedFormulaFilterValue, type TFiltrationAccessibility, type TGradientsSetValue, type TGroupLevelRecord, type THSLTuple, type THintPlacement, type TLaunchActionParams, type TLimitedColor, type TMeasureAddButtonSelectOption, type TMigrateProcessor, type TMigrationStruct, type TParameterFromDataModel, type TProcessIndicatorValue, type TRGBTuple, type TRecordAccessor, type TSchemaType, type TSelectChildOptions, type TSelectFetchNodes, type TSelectivePartial, type TSettingsFilter, type TSettingsOf, type TSortDirection, type TTabsHorizontalAlignment, type TUpdateSelection, type TValuePath, type TVersion, type TViewActionParameter, type TWidgetActionParameter, type TWidgetContainer, type TWidgetDimensionData, type TWidgetDimensionUnion, type TWidgetFilterValue, type TWidgetFiltering, type TWidgetIndicatorAggregationValue, type TWidgetIndicatorConversionValue, type TWidgetIndicatorDurationValue, type TWidgetIndicatorTimeValue, type TWidgetLevelRecord, type TWidgetMeasureData, type TWidgetSortingValue, type TWidgetVariable, type TWidgetsPaletteValue, type TZod, VersionedSchemaFactory, ViewActionParameterSchema, ViewActionSchema, WidgetActionParameterSchema, WidgetActionSchema, WidgetColumnIndicatorSchema, WidgetDimensionHierarchySchema, WidgetDimensionInHierarchySchema, WidgetDimensionSchema, WidgetIndicatorAggregationValueSchema, WidgetIndicatorConversionValueSchema, WidgetIndicatorDurationValueSchema, WidgetIndicatorFormulaValueSchema, WidgetIndicatorSchema, WidgetIndicatorTemplateValueSchema, WidgetIndicatorTimeValueSchema, WidgetMeasureAggregationValueSchema, WidgetMeasureSchema, WidgetPresetSettingsSchema, WidgetSortingIndicatorSchema, WidgetSortingValueSchema, apiVersion, apiVersions, applyIndexToArrayFormula, availableFormatsBySimpleType, bindContentWithIndicator, bindContentsWithIndicators, checkDisplayCondition, clearMultiLineComments, clearSingleLineComments, colors, conversionTemplate, convertFiltersToFormula, convertToFormulasChain, countExecutionsTemplate, createEscaper, createAggregationTemplate as createMeasureAggregationTemplate, curlyBracketsContentPattern, dashboardLinkRegExp, defaultActionsConfig, dimensionAggregationTemplates, dimensionTemplateFormulas, displayConditionTemplate, doubleQuoteContentPattern, durationTemplates, escapeCurlyBracketLinkName, escapeDoubleQuoteLinkName, eventMeasureTemplateFormulas, extendWithMeta, fillTemplateSql, formulaFilterMethods, generateColumnFormula, getColorByIndex, getDefaultSortOrders, getDimensionFormula, getDisplayConditionFormula, getEventMeasureFormula, getMeasureFormula, getParentMeta, getProcessDimensionValueFormula, getRuleColor, getTransitionMeasureFormula, hasInMetaChain, hexToRgb, inheritDisplayConditionFromHierarchy, interpolateHexColor, isDimensionProcessFilter, isDimensionsHierarchy, isFormulaFilterValue, isValidColor, mapDimensionsToInputs, mapEventMeasuresToInputs, mapFormulaFilterToCalculatorInput, mapFormulaFiltersToInputs, mapMeasuresToInputs, mapSettingsFiltersToInputs, mapSortingToInputs, mapTransitionMeasuresToInputs, measureInnerTemplateFormulas, measureTemplateFormulas, omitWithMeta, parseClickHouseType, parseIndicatorLink, prepareConversionParams, prepareDimensionAggregationParams, prepareDurationParams, prepareFormulaForSql, prepareMeasureAggregationParams, prepareSortOrders, prepareTimeParams, prepareValuesForSql, replaceDisplayCondition, replaceFiltersBySelection, replaceHierarchiesWithDimensions, selectDimensionFromHierarchy, themed, timeTemplates, transitionMeasureTemplateFormulas, unescapeSpecialCharacters, updateDefaultModeSelection, updateSingleModeSelection, workspaceLinkRegExp };
package/dist/index.esm.js CHANGED
@@ -231,6 +231,12 @@ var clamp = function (value, min, max) {
231
231
  }
232
232
  return value;
233
233
  };
234
+ function mapValues(obj, fn) {
235
+ return Object.fromEntries(Object.entries(obj).map(function (_a) {
236
+ var _b = __read(_a, 2), key = _b[0], value = _b[1];
237
+ return [key, fn(value, key)];
238
+ }));
239
+ }
234
240
  /** Добавляет свойства к функции */
235
241
  function assignPropsToFn(fn, props) {
236
242
  return Object.assign(fn, props);
@@ -275,6 +281,31 @@ var VersionedSchemaFactory = /** @class */ (function () {
275
281
  });
276
282
  };
277
283
  };
284
+ /**
285
+ * Оборачивает фабрику схемы, добавляя кеширование результата.
286
+ *
287
+ * Предполагается, что `z` — синглтон (один экземпляр на всё приложение),
288
+ * поэтому достаточно закешировать единственный результат.
289
+ *
290
+ * Вызовы с дополнительными аргументами (restArgs) не кешируются,
291
+ * так как результат может зависеть от их значений.
292
+ */
293
+ VersionedSchemaFactory.withCache = function (schemaFactory) {
294
+ var cached;
295
+ return (function (z) {
296
+ var restArgs = [];
297
+ for (var _i = 1; _i < arguments.length; _i++) {
298
+ restArgs[_i - 1] = arguments[_i];
299
+ }
300
+ if (restArgs.length > 0) {
301
+ return schemaFactory.apply(void 0, __spreadArray([z], __read(restArgs), false));
302
+ }
303
+ if (cached === undefined) {
304
+ cached = schemaFactory(z);
305
+ }
306
+ return cached;
307
+ });
308
+ };
278
309
  /** Построить версионированную схему */
279
310
  VersionedSchemaFactory.build = function (_a) {
280
311
  var _this = this;
@@ -283,20 +314,23 @@ var VersionedSchemaFactory = /** @class */ (function () {
283
314
  if (!latestFactory) {
284
315
  throw new Error("Не найдено записи в 'history' по 'latestVersion'");
285
316
  }
286
- var map = this.annotateSchema(meta);
287
- var schema = assignPropsToFn(map(latestFactory), {
317
+ var annotate = this.annotateSchema(meta);
318
+ var preparedHistory = mapValues(history, function (factory) {
319
+ return _this.withCache(annotate(factory));
320
+ });
321
+ var schema = assignPropsToFn(preparedHistory[latestVersion], {
288
322
  forVersion: function (targetVersion) {
289
323
  if (targetVersion === null || targetVersion === undefined) {
290
- return map(latestFactory);
324
+ return preparedHistory[latestVersion];
291
325
  }
292
- if (targetVersion in history) {
293
- return map(history[targetVersion]);
326
+ if (targetVersion in preparedHistory) {
327
+ return preparedHistory[targetVersion];
294
328
  }
295
- var closestVersion = _this.findClosestVersion(Object.keys(history), targetVersion, VersionedSchemaFactory.compareVersions);
296
- if (closestVersion === undefined || !(closestVersion in history)) {
329
+ var closestVersion = _this.findClosestVersion(Object.keys(preparedHistory), targetVersion, VersionedSchemaFactory.compareVersions);
330
+ if (closestVersion === undefined || !(closestVersion in preparedHistory)) {
297
331
  throw new Error("\u041D\u0435 \u043D\u0430\u0439\u0434\u0435\u043D\u043E \u043F\u043E\u0434\u0445\u043E\u0434\u044F\u0449\u0435\u0439 \u0441\u0445\u0435\u043C\u044B \u0434\u043B\u044F \u0432\u0435\u0440\u0441\u0438\u0438 '".concat(targetVersion, "'"));
298
332
  }
299
- return map(history[closestVersion]);
333
+ return preparedHistory[closestVersion];
300
334
  },
301
335
  });
302
336
  return schema;
@@ -696,12 +730,84 @@ var FormulaNullableSchema = SchemaRegistry.define({
696
730
  },
697
731
  });
698
732
 
733
+ // NOTE: В будущем можно сделать fluent-обёртку для цепочных вызовов:
734
+ // withMetaDecorator(schema).omit({ field: true }).extend({ newField: z.string() })
735
+ // Это позволит избежать вложенных вызовов omitWithMeta/extendWithMeta.
736
+ var PARENT_META_KEY = "parent";
737
+ /**
738
+ * Возвращает родительскую мету схемы, установленную через extendWithMeta / omitWithMeta.
739
+ * Используй для обхода цепочки наследования схем.
740
+ */
741
+ function getParentMeta(meta) {
742
+ return meta[PARENT_META_KEY];
743
+ }
744
+ function inheritMeta(target, source) {
745
+ var _a;
746
+ var sourceMeta = source.meta();
747
+ return sourceMeta !== undefined ? target.meta((_a = {}, _a[PARENT_META_KEY] = sourceMeta, _a)) : target;
748
+ }
749
+ /**
750
+ * Расширяет Zod-схему дополнительными полями, сохраняя цепочку наследования мет.
751
+ *
752
+ * Мета базовой схемы сохраняется как `parent` в мете расширенной схемы — формируя
753
+ * иммутабельный связанный список.
754
+ *
755
+ * Используй вместо `.extend()` при расширении схем, задекларированных через
756
+ * `SchemaRegistry.define`, — это обязательное условие корректной работы миграций.
757
+ *
758
+ * @example
759
+ * // Вместо:
760
+ * DimensionSchema(z).extend({ color: ColorSchema(z) })
761
+ *
762
+ * // Используй:
763
+ * extendWithMeta(DimensionSchema(z), { color: ColorSchema(z) })
764
+ */
765
+ function extendWithMeta(schema, extension) {
766
+ return inheritMeta(schema.extend(extension), schema);
767
+ }
768
+ /**
769
+ * Создаёт Zod-схему с удалёнными полями, сохраняя цепочку наследования мет.
770
+ *
771
+ * Мета базовой схемы сохраняется как `parent` в мете результирующей схемы.
772
+ *
773
+ * Используй вместо `.omit()` при работе со схемами, задекларированными через
774
+ * `SchemaRegistry.define`, — это обязательное условие корректной работы миграций.
775
+ *
776
+ * @example
777
+ * // Вместо:
778
+ * BaseWidgetSettingsSchema(z).omit({ paddings: true })
779
+ *
780
+ * // Используй:
781
+ * omitWithMeta(BaseWidgetSettingsSchema(z), { paddings: true })
782
+ */
783
+ function omitWithMeta(schema, keys) {
784
+ return inheritMeta(schema.omit(keys), schema);
785
+ }
786
+ /**
787
+ * Проверяет, есть ли в цепочке наследования мет узел, удовлетворяющий предикату.
788
+ *
789
+ * Обходит цепочку от текущей меты к корню через ссылки parent, установленные
790
+ * функциями extendWithMeta / omitWithMeta.
791
+ *
792
+ * @example
793
+ * hasInMetaChain(schema.meta(), (meta) => meta.type === "WidgetDimension")
794
+ */
795
+ function hasInMetaChain(meta, predicate) {
796
+ var current = meta;
797
+ while (current !== undefined) {
798
+ if (predicate(current))
799
+ return true;
800
+ current = getParentMeta(current);
801
+ }
802
+ return false;
803
+ }
804
+
699
805
  var WidgetIndicatorSchema = SchemaRegistry.define({
700
806
  key: "WidgetIndicator",
701
807
  latestVersion: "17",
702
808
  history: {
703
809
  "17": function (z) {
704
- return AutoIdentifiedArrayItemSchema.forVersion("17")(z).extend({
810
+ return extendWithMeta(AutoIdentifiedArrayItemSchema.forVersion("17")(z), {
705
811
  name: z.string(),
706
812
  });
707
813
  },
@@ -752,7 +858,7 @@ var WidgetColumnIndicatorSchema = SchemaRegistry.define({
752
858
  latestVersion: "17",
753
859
  history: {
754
860
  "17": function (z) {
755
- return WidgetIndicatorSchema.forVersion("17")(z).extend({
861
+ return extendWithMeta(WidgetIndicatorSchema.forVersion("17")(z), {
756
862
  dbDataType: z.string().optional(),
757
863
  format: FormatSchema.forVersion("17")(z).optional(),
758
864
  formatting: FormattingSchema.forVersion("17")(z).optional(),
@@ -807,7 +913,7 @@ var MeasureValueSchema = SchemaRegistry.define({
807
913
  "17": function (z) {
808
914
  return z.discriminatedUnion("mode", [
809
915
  WidgetIndicatorFormulaValueSchema.forVersion("17")(z),
810
- WidgetIndicatorTemplateValueSchema.forVersion("17")(z).extend({
916
+ extendWithMeta(WidgetIndicatorTemplateValueSchema.forVersion("17")(z), {
811
917
  innerTemplateName: z.enum(EMeasureInnerTemplateNames).optional(),
812
918
  }),
813
919
  ]);
@@ -821,7 +927,7 @@ var DimensionValueSchema = SchemaRegistry.define({
821
927
  "17": function (z) {
822
928
  return z.discriminatedUnion("mode", [
823
929
  WidgetIndicatorFormulaValueSchema.forVersion("17")(z),
824
- WidgetIndicatorTemplateValueSchema.forVersion("17")(z).extend({
930
+ extendWithMeta(WidgetIndicatorTemplateValueSchema.forVersion("17")(z), {
825
931
  innerTemplateName: z.never().optional(),
826
932
  }),
827
933
  ]);
@@ -855,7 +961,7 @@ var WidgetMeasureAggregationValueSchema = SchemaRegistry.define({
855
961
  latestVersion: "17",
856
962
  history: {
857
963
  "17": function (z) {
858
- return WidgetIndicatorAggregationValueSchema.forVersion("17")(z).extend({
964
+ return extendWithMeta(WidgetIndicatorAggregationValueSchema.forVersion("17")(z), {
859
965
  outerAggregation: z.enum(EOuterAggregation),
860
966
  });
861
967
  },
@@ -887,11 +993,11 @@ var WidgetDimensionSchema = SchemaRegistry.define({
887
993
  latestVersion: "17",
888
994
  history: {
889
995
  "17": function (z) {
890
- return WidgetColumnIndicatorSchema.forVersion("17")(z).extend({
996
+ return extendWithMeta(WidgetColumnIndicatorSchema.forVersion("17")(z), {
891
997
  value: z
892
998
  .discriminatedUnion("mode", [
893
999
  DimensionValueSchema.forVersion("17")(z),
894
- WidgetIndicatorAggregationValueSchema.forVersion("17")(z).extend({
1000
+ extendWithMeta(WidgetIndicatorAggregationValueSchema.forVersion("17")(z), {
895
1001
  innerTemplateName: z.string().optional(),
896
1002
  }),
897
1003
  WidgetIndicatorTimeValueSchema.forVersion("17")(z),
@@ -906,7 +1012,9 @@ var WidgetDimensionInHierarchySchema = SchemaRegistry.define({
906
1012
  key: "WidgetDimensionInHierarchy",
907
1013
  latestVersion: "17",
908
1014
  history: {
909
- "17": function (z) { return WidgetDimensionSchema.forVersion("17")(z).omit({ displayCondition: true }); },
1015
+ "17": function (z) {
1016
+ return omitWithMeta(WidgetDimensionSchema.forVersion("17")(z), { displayCondition: true });
1017
+ },
910
1018
  },
911
1019
  });
912
1020
  var WidgetDimensionHierarchySchema = SchemaRegistry.define({
@@ -914,7 +1022,7 @@ var WidgetDimensionHierarchySchema = SchemaRegistry.define({
914
1022
  latestVersion: "17",
915
1023
  history: {
916
1024
  "17": function (z, dimensionSchema) {
917
- return AutoIdentifiedArrayItemSchema.forVersion("17")(z).extend({
1025
+ return extendWithMeta(AutoIdentifiedArrayItemSchema.forVersion("17")(z), {
918
1026
  name: z.string(),
919
1027
  // Для иерархии является дискриминатором, для него нельзя задавать дефолтное значение.
920
1028
  hierarchyDimensions: z.array(dimensionSchema),
@@ -952,7 +1060,7 @@ var WidgetIndicatorDurationValueSchema = SchemaRegistry.define({
952
1060
  latestVersion: "17",
953
1061
  history: {
954
1062
  "17": function (z) {
955
- return WidgetIndicatorConversionValueSchema.forVersion("17")(z).extend({
1063
+ return extendWithMeta(WidgetIndicatorConversionValueSchema.forVersion("17")(z), {
956
1064
  mode: z.literal(EWidgetIndicatorValueModes.DURATION),
957
1065
  templateName: z.string(),
958
1066
  startEventAppearances: z.enum(EEventAppearances),
@@ -966,7 +1074,7 @@ var WidgetMeasureSchema = SchemaRegistry.define({
966
1074
  latestVersion: "17",
967
1075
  history: {
968
1076
  "17": function (z) {
969
- return WidgetColumnIndicatorSchema.forVersion("17")(z).extend({
1077
+ return extendWithMeta(WidgetColumnIndicatorSchema.forVersion("17")(z), {
970
1078
  value: z
971
1079
  .discriminatedUnion("mode", [
972
1080
  MeasureValueSchema.forVersion("17")(z),
@@ -984,7 +1092,7 @@ var MarkdownMeasureSchema = SchemaRegistry.define({
984
1092
  latestVersion: "17",
985
1093
  history: {
986
1094
  "17": function (z) {
987
- return WidgetMeasureSchema.forVersion("17")(z).extend({
1095
+ return extendWithMeta(WidgetMeasureSchema.forVersion("17")(z), {
988
1096
  displaySign: z.enum(EMarkdownDisplayMode).default(EMarkdownDisplayMode.NONE),
989
1097
  });
990
1098
  },
@@ -995,7 +1103,7 @@ var WidgetSortingIndicatorSchema = SchemaRegistry.define({
995
1103
  latestVersion: "17",
996
1104
  history: {
997
1105
  "17": function (z) {
998
- return WidgetIndicatorSchema.forVersion("17")(z).extend({
1106
+ return extendWithMeta(WidgetIndicatorSchema.forVersion("17")(z), {
999
1107
  direction: SortDirectionSchema.forVersion("17")(z),
1000
1108
  value: WidgetSortingValueSchema.forVersion("17")(z),
1001
1109
  });
@@ -1026,7 +1134,7 @@ var ProcessIndicatorSchema = SchemaRegistry.define({
1026
1134
  latestVersion: "17",
1027
1135
  history: {
1028
1136
  "17": function (z) {
1029
- return WidgetIndicatorSchema.forVersion("17")(z).extend({
1137
+ return extendWithMeta(WidgetIndicatorSchema.forVersion("17")(z), {
1030
1138
  value: ProcessIndicatorValueSchema.forVersion("17")(z).optional(),
1031
1139
  dbDataType: z.string().optional(),
1032
1140
  format: FormatSchema.forVersion("17")(z).optional(),
@@ -1090,10 +1198,10 @@ var DimensionProcessFilterSchema = SchemaRegistry.define({
1090
1198
  "17": function (z) {
1091
1199
  return z.object({
1092
1200
  value: z.union([
1093
- WidgetIndicatorAggregationValueSchema.forVersion("17")(z).extend({
1201
+ extendWithMeta(WidgetIndicatorAggregationValueSchema.forVersion("17")(z), {
1094
1202
  outerAggregation: z.enum(EOuterAggregation),
1095
1203
  }),
1096
- WidgetIndicatorAggregationValueSchema.forVersion("17")(z).extend({
1204
+ extendWithMeta(WidgetIndicatorAggregationValueSchema.forVersion("17")(z), {
1097
1205
  innerTemplateName: z.string().optional(),
1098
1206
  }),
1099
1207
  WidgetIndicatorTimeValueSchema.forVersion("17")(z),
@@ -1130,7 +1238,7 @@ var ActionOnClickParameterCommonSchema = SchemaRegistry.define({
1130
1238
  latestVersion: "17",
1131
1239
  history: {
1132
1240
  "17": function (z) {
1133
- return AutoIdentifiedArrayItemSchema.forVersion("17")(z).extend({
1241
+ return extendWithMeta(AutoIdentifiedArrayItemSchema.forVersion("17")(z), {
1134
1242
  name: z.string(),
1135
1243
  });
1136
1244
  },
@@ -1321,7 +1429,7 @@ var ActionCommonSchema = SchemaRegistry.define({
1321
1429
  latestVersion: "17",
1322
1430
  history: {
1323
1431
  "17": function (z) {
1324
- return AutoIdentifiedArrayItemSchema.forVersion("17")(z).extend({
1432
+ return extendWithMeta(AutoIdentifiedArrayItemSchema.forVersion("17")(z), {
1325
1433
  name: z.string(),
1326
1434
  });
1327
1435
  },
@@ -1332,7 +1440,7 @@ var ActionDrillDownSchema = SchemaRegistry.define({
1332
1440
  latestVersion: "17",
1333
1441
  history: {
1334
1442
  "17": function (z) {
1335
- return ActionCommonSchema.forVersion("17")(z).extend({
1443
+ return extendWithMeta(ActionCommonSchema.forVersion("17")(z), {
1336
1444
  type: z.literal(EActionTypes.DRILL_DOWN),
1337
1445
  variables: z.array(ActionOnClickParameterSchema.forVersion("17")(z)).default([]),
1338
1446
  });
@@ -1344,7 +1452,7 @@ var ActionGoToURLSchema = SchemaRegistry.define({
1344
1452
  latestVersion: "17",
1345
1453
  history: {
1346
1454
  "17": function (z) {
1347
- return ActionCommonSchema.forVersion("17")(z).extend({
1455
+ return extendWithMeta(ActionCommonSchema.forVersion("17")(z), {
1348
1456
  type: z.literal(EActionTypes.OPEN_URL),
1349
1457
  url: z.string(),
1350
1458
  newWindow: z.boolean().default(true),
@@ -1379,7 +1487,7 @@ var ActionRunScriptSchema = SchemaRegistry.define({
1379
1487
  latestVersion: "17",
1380
1488
  history: {
1381
1489
  "17": function (z) {
1382
- return ActionCommonSchema.forVersion("17")(z).extend({
1490
+ return extendWithMeta(ActionCommonSchema.forVersion("17")(z), {
1383
1491
  type: z.literal(EActionTypes.EXECUTE_SCRIPT),
1384
1492
  parameters: z.array(ActionOnClickParameterSchema.forVersion("17")(z)).default([]),
1385
1493
  scriptKey: z.string(),
@@ -1398,7 +1506,7 @@ var ActionUpdateVariableSchema = SchemaRegistry.define({
1398
1506
  latestVersion: "17",
1399
1507
  history: {
1400
1508
  "17": function (z) {
1401
- return ActionCommonSchema.forVersion("17")(z).extend({
1509
+ return extendWithMeta(ActionCommonSchema.forVersion("17")(z), {
1402
1510
  type: z.literal(EActionTypes.UPDATE_VARIABLE),
1403
1511
  variables: z.array(ActionOnClickParameterSchema.forVersion("17")(z)).default([]),
1404
1512
  });
@@ -1439,7 +1547,7 @@ var ActionOpenViewCommonSchema = SchemaRegistry.define({
1439
1547
  latestVersion: "17",
1440
1548
  history: {
1441
1549
  "17": function (z) {
1442
- return ActionCommonSchema.forVersion("17")(z).extend({
1550
+ return extendWithMeta(ActionCommonSchema.forVersion("17")(z), {
1443
1551
  type: z.literal(EActionTypes.OPEN_VIEW),
1444
1552
  variables: z.array(ActionOnClickParameterSchema.forVersion("17")(z)).default([]),
1445
1553
  });
@@ -1452,18 +1560,18 @@ var ActionOpenViewSchema = SchemaRegistry.define({
1452
1560
  history: {
1453
1561
  "17": function (z) {
1454
1562
  return z.intersection(z.discriminatedUnion("mode", [
1455
- ActionOpenViewCommonSchema.forVersion("17")(z).extend({
1563
+ extendWithMeta(ActionOpenViewCommonSchema.forVersion("17")(z), {
1456
1564
  mode: z.literal(EViewMode.GENERATED_BY_SCRIPT),
1457
1565
  scriptKey: z.string().optional(),
1458
1566
  parameters: z.array(ActionOnClickParameterSchema.forVersion("17")(z)).default([]),
1459
1567
  displayName: z.string().default(""),
1460
1568
  }),
1461
- ActionOpenViewCommonSchema.forVersion("17")(z).extend({
1569
+ extendWithMeta(ActionOpenViewCommonSchema.forVersion("17")(z), {
1462
1570
  mode: z.literal(EViewMode.EXISTED_VIEW),
1463
1571
  viewKey: z.string().optional(),
1464
1572
  parameters: z.array(ActionOnClickParameterSchema.forVersion("17")(z)).default([]),
1465
1573
  }),
1466
- ActionOpenViewCommonSchema.forVersion("17")(z).extend({
1574
+ extendWithMeta(ActionOpenViewCommonSchema.forVersion("17")(z), {
1467
1575
  mode: z.literal(EViewMode.EMPTY),
1468
1576
  placeholderName: z.string().optional(),
1469
1577
  openIn: z.literal(EViewOpenIn.PLACEHOLDER),
@@ -1492,7 +1600,7 @@ var WidgetActionParameterCommonSchema = SchemaRegistry.define({
1492
1600
  latestVersion: "17",
1493
1601
  history: {
1494
1602
  "17": function (z) {
1495
- return AutoIdentifiedArrayItemSchema.forVersion("17")(z).extend({
1603
+ return extendWithMeta(AutoIdentifiedArrayItemSchema.forVersion("17")(z), {
1496
1604
  name: z.string(),
1497
1605
  displayName: z.string().default(""),
1498
1606
  isHidden: z.boolean().default(false),
@@ -1523,7 +1631,7 @@ var WidgetActionSchema = SchemaRegistry.define({
1523
1631
  latestVersion: "17",
1524
1632
  history: {
1525
1633
  "17": function (z) {
1526
- return ActionCommonSchema.forVersion("17")(z).extend({
1634
+ return extendWithMeta(ActionCommonSchema.forVersion("17")(z), {
1527
1635
  parameters: z.array(WidgetActionParameterSchema.forVersion("17")(z)).default([]),
1528
1636
  type: z.literal(EActionTypes.EXECUTE_SCRIPT),
1529
1637
  scriptKey: z.string(),
@@ -1543,7 +1651,7 @@ var ViewActionParameterSchema = SchemaRegistry.define({
1543
1651
  latestVersion: "17",
1544
1652
  history: {
1545
1653
  "17": function (z) {
1546
- return z.intersection(AutoIdentifiedArrayItemSchema.forVersion("17")(z).extend({ name: z.string() }), z.discriminatedUnion("inputMethod", [
1654
+ return z.intersection(extendWithMeta(AutoIdentifiedArrayItemSchema.forVersion("17")(z), { name: z.string() }), z.discriminatedUnion("inputMethod", [
1547
1655
  ParameterFromAggregationSchema.forVersion("17")(z),
1548
1656
  ParameterFromVariableSchema.forVersion("17")(z),
1549
1657
  ]));
@@ -1555,7 +1663,7 @@ var ViewActionSchema = SchemaRegistry.define({
1555
1663
  latestVersion: "17",
1556
1664
  history: {
1557
1665
  "17": function (z) {
1558
- return AutoIdentifiedArrayItemSchema.forVersion("17")(z).extend({
1666
+ return extendWithMeta(AutoIdentifiedArrayItemSchema.forVersion("17")(z), {
1559
1667
  name: z.string(),
1560
1668
  buttonType: z.enum(EActionButtonsTypes).default(EActionButtonsTypes.BASE),
1561
1669
  type: z.literal(EActionTypes.EXECUTE_SCRIPT).default(EActionTypes.EXECUTE_SCRIPT),
@@ -1586,7 +1694,7 @@ var ActionButtonSchema = SchemaRegistry.define({
1586
1694
  latestVersion: "17",
1587
1695
  history: {
1588
1696
  "17": function (z) {
1589
- return AutoIdentifiedArrayItemSchema.forVersion("17")(z).extend({
1697
+ return extendWithMeta(AutoIdentifiedArrayItemSchema.forVersion("17")(z), {
1590
1698
  name: z.string(),
1591
1699
  onClick: z.array(WidgetActionSchema.forVersion("17")(z)).default([]),
1592
1700
  buttonType: z.enum(EActionButtonsTypes).default(EActionButtonsTypes.BASE),
@@ -3487,4 +3595,4 @@ var themed = function (scheme, selectThemeValue) {
3487
3595
  return scheme.meta((_a = {}, _a[ESettingsSchemaMetaKey.themeValue] = selectThemeValue, _a));
3488
3596
  };
3489
3597
 
3490
- export { ActionButtonSchema, ActionDrillDownSchema, ActionGoToURLSchema, ActionOnClickParameterSchema, ActionOpenInSchema, ActionOpenViewSchema, ActionRunScriptSchema, ActionSchema, ActionUpdateVariableSchema, ActionsOnClickSchema, AutoIdentifiedArrayItemSchema, BaseWidgetSettingsSchema, ColorAutoSchema, ColorBaseSchema, ColorByDimensionSchema, ColorDisabledSchema, ColorFormulaSchema, ColorGradientSchema, ColorRuleSchema, ColorSchema, ColorValuesSchema, ColoredValueSchema, ColumnIndicatorValueSchema, DimensionProcessFilterSchema, DimensionValueSchema, DisplayConditionSchema, EActionButtonsTypes, EActionTypes, EActivateConditionMode, EAutoUpdateMode, ECalculatorFilterMethods, EClickHouseBaseTypes, EColorMode, EControlType, ECustomSelectTemplates, EDataModelOption, EDimensionAggregationTemplateName, EDimensionProcessFilterTimeUnit, EDimensionTemplateNames, EDisplayConditionMode, EDrawerPlacement, EDurationTemplateName, EDurationUnit, EEventAppearances, EEventMeasureTemplateNames, EFontWeight, EFormatOrFormattingMode, EFormulaFilterFieldKeys, EHeightMode, EIndicatorType, ELastTimeUnit, EMarkdownDisplayMode, EMeasureAggregationTemplateName, EMeasureInnerTemplateNames, EMeasureTemplateNames, EOuterAggregation, EProcessFilterNames, ESelectOptionTypes, ESettingsSchemaMetaKey, ESimpleDataType, ESimpleInputType, ESortDirection, ESortingValueModes, ESystemRecordKey, ETransitionMeasureTemplateNames, EUnitMode, EViewMode, EViewOpenIn, EWidgetActionInputMethod, EWidgetFilterMode, EWidgetIndicatorType, EWidgetIndicatorValueModes, ExtendedFormulaFilterValueSchema, FormatSchema, FormattingSchema, FormulaFilterValueSchema, FormulaNullableSchema, FormulaSchema, KeyNullableSchema, MarkdownMeasureSchema, MeasureValueSchema, NameNullableSchema, OuterAggregation, ParameterFromAggregationSchema, ParameterFromColumnSchema, ParameterFromDataModelSchema, ParameterFromDynamicListSchema, ParameterFromEndEventSchema, ParameterFromEventSchema, ParameterFromFormulaSchema, ParameterFromManualInputSchema, ParameterFromStartEventSchema, ParameterFromStaticListSchema, ParameterFromVariableSchema, ProcessIndicatorSchema, ProcessIndicatorValueSchema, RangeSchema, SchemaRegistryReader, SettingsFilterSchema, SortDirectionSchema, SortOrderSchema, VersionedSchemaFactory, ViewActionParameterSchema, ViewActionSchema, WidgetActionParameterSchema, WidgetActionSchema, WidgetColumnIndicatorSchema, WidgetDimensionHierarchySchema, WidgetDimensionInHierarchySchema, WidgetDimensionSchema, WidgetIndicatorAggregationValueSchema, WidgetIndicatorConversionValueSchema, WidgetIndicatorDurationValueSchema, WidgetIndicatorFormulaValueSchema, WidgetIndicatorSchema, WidgetIndicatorTemplateValueSchema, WidgetIndicatorTimeValueSchema, WidgetMeasureAggregationValueSchema, WidgetMeasureSchema, WidgetPresetSettingsSchema, WidgetSortingIndicatorSchema, WidgetSortingValueSchema, apiVersion, apiVersions, applyIndexToArrayFormula, availableFormatsBySimpleType, bindContentWithIndicator, bindContentsWithIndicators, checkDisplayCondition, clearMultiLineComments, clearSingleLineComments, colors, conversionTemplate, convertFiltersToFormula, convertToFormulasChain, countExecutionsTemplate, createEscaper, createAggregationTemplate as createMeasureAggregationTemplate, curlyBracketsContentPattern, dashboardLinkRegExp, defaultActionsConfig, dimensionAggregationTemplates, dimensionTemplateFormulas, displayConditionTemplate, doubleQuoteContentPattern, durationTemplates, escapeCurlyBracketLinkName, escapeDoubleQuoteLinkName, eventMeasureTemplateFormulas, fillTemplateSql, formulaFilterMethods, generateColumnFormula, getColorByIndex, getDefaultSortOrders, getDimensionFormula, getDisplayConditionFormula, getEventMeasureFormula, getMeasureFormula, getProcessDimensionValueFormula, getRuleColor, getTransitionMeasureFormula, hexToRgb, inheritDisplayConditionFromHierarchy, interpolateHexColor, isDimensionProcessFilter, isDimensionsHierarchy, isFormulaFilterValue, isValidColor, mapDimensionsToInputs, mapEventMeasuresToInputs, mapFormulaFilterToCalculatorInput, mapFormulaFiltersToInputs, mapMeasuresToInputs, mapSettingsFiltersToInputs, mapSortingToInputs, mapTransitionMeasuresToInputs, measureInnerTemplateFormulas, measureTemplateFormulas, parseClickHouseType, parseIndicatorLink, prepareConversionParams, prepareDimensionAggregationParams, prepareDurationParams, prepareFormulaForSql, prepareMeasureAggregationParams, prepareSortOrders, prepareTimeParams, prepareValuesForSql, replaceDisplayCondition, replaceFiltersBySelection, replaceHierarchiesWithDimensions, selectDimensionFromHierarchy, themed, timeTemplates, transitionMeasureTemplateFormulas, unescapeSpecialCharacters, updateDefaultModeSelection, updateSingleModeSelection, workspaceLinkRegExp };
3598
+ export { ActionButtonSchema, ActionDrillDownSchema, ActionGoToURLSchema, ActionOnClickParameterSchema, ActionOpenInSchema, ActionOpenViewSchema, ActionRunScriptSchema, ActionSchema, ActionUpdateVariableSchema, ActionsOnClickSchema, AutoIdentifiedArrayItemSchema, BaseWidgetSettingsSchema, ColorAutoSchema, ColorBaseSchema, ColorByDimensionSchema, ColorDisabledSchema, ColorFormulaSchema, ColorGradientSchema, ColorRuleSchema, ColorSchema, ColorValuesSchema, ColoredValueSchema, ColumnIndicatorValueSchema, DimensionProcessFilterSchema, DimensionValueSchema, DisplayConditionSchema, EActionButtonsTypes, EActionTypes, EActivateConditionMode, EAutoUpdateMode, ECalculatorFilterMethods, EClickHouseBaseTypes, EColorMode, EControlType, ECustomSelectTemplates, EDataModelOption, EDimensionAggregationTemplateName, EDimensionProcessFilterTimeUnit, EDimensionTemplateNames, EDisplayConditionMode, EDrawerPlacement, EDurationTemplateName, EDurationUnit, EEventAppearances, EEventMeasureTemplateNames, EFontWeight, EFormatOrFormattingMode, EFormulaFilterFieldKeys, EHeightMode, EIndicatorType, ELastTimeUnit, EMarkdownDisplayMode, EMeasureAggregationTemplateName, EMeasureInnerTemplateNames, EMeasureTemplateNames, EOuterAggregation, EProcessFilterNames, ESelectOptionTypes, ESettingsSchemaMetaKey, ESimpleDataType, ESimpleInputType, ESortDirection, ESortingValueModes, ESystemRecordKey, ETransitionMeasureTemplateNames, EUnitMode, EViewMode, EViewOpenIn, EWidgetActionInputMethod, EWidgetFilterMode, EWidgetIndicatorType, EWidgetIndicatorValueModes, ExtendedFormulaFilterValueSchema, FormatSchema, FormattingSchema, FormulaFilterValueSchema, FormulaNullableSchema, FormulaSchema, KeyNullableSchema, MarkdownMeasureSchema, MeasureValueSchema, NameNullableSchema, OuterAggregation, ParameterFromAggregationSchema, ParameterFromColumnSchema, ParameterFromDataModelSchema, ParameterFromDynamicListSchema, ParameterFromEndEventSchema, ParameterFromEventSchema, ParameterFromFormulaSchema, ParameterFromManualInputSchema, ParameterFromStartEventSchema, ParameterFromStaticListSchema, ParameterFromVariableSchema, ProcessIndicatorSchema, ProcessIndicatorValueSchema, RangeSchema, SchemaRegistryReader, SettingsFilterSchema, SortDirectionSchema, SortOrderSchema, VersionedSchemaFactory, ViewActionParameterSchema, ViewActionSchema, WidgetActionParameterSchema, WidgetActionSchema, WidgetColumnIndicatorSchema, WidgetDimensionHierarchySchema, WidgetDimensionInHierarchySchema, WidgetDimensionSchema, WidgetIndicatorAggregationValueSchema, WidgetIndicatorConversionValueSchema, WidgetIndicatorDurationValueSchema, WidgetIndicatorFormulaValueSchema, WidgetIndicatorSchema, WidgetIndicatorTemplateValueSchema, WidgetIndicatorTimeValueSchema, WidgetMeasureAggregationValueSchema, WidgetMeasureSchema, WidgetPresetSettingsSchema, WidgetSortingIndicatorSchema, WidgetSortingValueSchema, apiVersion, apiVersions, applyIndexToArrayFormula, availableFormatsBySimpleType, bindContentWithIndicator, bindContentsWithIndicators, checkDisplayCondition, clearMultiLineComments, clearSingleLineComments, colors, conversionTemplate, convertFiltersToFormula, convertToFormulasChain, countExecutionsTemplate, createEscaper, createAggregationTemplate as createMeasureAggregationTemplate, curlyBracketsContentPattern, dashboardLinkRegExp, defaultActionsConfig, dimensionAggregationTemplates, dimensionTemplateFormulas, displayConditionTemplate, doubleQuoteContentPattern, durationTemplates, escapeCurlyBracketLinkName, escapeDoubleQuoteLinkName, eventMeasureTemplateFormulas, extendWithMeta, fillTemplateSql, formulaFilterMethods, generateColumnFormula, getColorByIndex, getDefaultSortOrders, getDimensionFormula, getDisplayConditionFormula, getEventMeasureFormula, getMeasureFormula, getParentMeta, getProcessDimensionValueFormula, getRuleColor, getTransitionMeasureFormula, hasInMetaChain, hexToRgb, inheritDisplayConditionFromHierarchy, interpolateHexColor, isDimensionProcessFilter, isDimensionsHierarchy, isFormulaFilterValue, isValidColor, mapDimensionsToInputs, mapEventMeasuresToInputs, mapFormulaFilterToCalculatorInput, mapFormulaFiltersToInputs, mapMeasuresToInputs, mapSettingsFiltersToInputs, mapSortingToInputs, mapTransitionMeasuresToInputs, measureInnerTemplateFormulas, measureTemplateFormulas, omitWithMeta, parseClickHouseType, parseIndicatorLink, prepareConversionParams, prepareDimensionAggregationParams, prepareDurationParams, prepareFormulaForSql, prepareMeasureAggregationParams, prepareSortOrders, prepareTimeParams, prepareValuesForSql, replaceDisplayCondition, replaceFiltersBySelection, replaceHierarchiesWithDimensions, selectDimensionFromHierarchy, themed, timeTemplates, transitionMeasureTemplateFormulas, unescapeSpecialCharacters, updateDefaultModeSelection, updateSingleModeSelection, workspaceLinkRegExp };
package/dist/index.js CHANGED
@@ -232,6 +232,12 @@ var clamp = function (value, min, max) {
232
232
  }
233
233
  return value;
234
234
  };
235
+ function mapValues(obj, fn) {
236
+ return Object.fromEntries(Object.entries(obj).map(function (_a) {
237
+ var _b = __read(_a, 2), key = _b[0], value = _b[1];
238
+ return [key, fn(value, key)];
239
+ }));
240
+ }
235
241
  /** Добавляет свойства к функции */
236
242
  function assignPropsToFn(fn, props) {
237
243
  return Object.assign(fn, props);
@@ -276,6 +282,31 @@ var VersionedSchemaFactory = /** @class */ (function () {
276
282
  });
277
283
  };
278
284
  };
285
+ /**
286
+ * Оборачивает фабрику схемы, добавляя кеширование результата.
287
+ *
288
+ * Предполагается, что `z` — синглтон (один экземпляр на всё приложение),
289
+ * поэтому достаточно закешировать единственный результат.
290
+ *
291
+ * Вызовы с дополнительными аргументами (restArgs) не кешируются,
292
+ * так как результат может зависеть от их значений.
293
+ */
294
+ VersionedSchemaFactory.withCache = function (schemaFactory) {
295
+ var cached;
296
+ return (function (z) {
297
+ var restArgs = [];
298
+ for (var _i = 1; _i < arguments.length; _i++) {
299
+ restArgs[_i - 1] = arguments[_i];
300
+ }
301
+ if (restArgs.length > 0) {
302
+ return schemaFactory.apply(void 0, __spreadArray([z], __read(restArgs), false));
303
+ }
304
+ if (cached === undefined) {
305
+ cached = schemaFactory(z);
306
+ }
307
+ return cached;
308
+ });
309
+ };
279
310
  /** Построить версионированную схему */
280
311
  VersionedSchemaFactory.build = function (_a) {
281
312
  var _this = this;
@@ -284,20 +315,23 @@ var VersionedSchemaFactory = /** @class */ (function () {
284
315
  if (!latestFactory) {
285
316
  throw new Error("Не найдено записи в 'history' по 'latestVersion'");
286
317
  }
287
- var map = this.annotateSchema(meta);
288
- var schema = assignPropsToFn(map(latestFactory), {
318
+ var annotate = this.annotateSchema(meta);
319
+ var preparedHistory = mapValues(history, function (factory) {
320
+ return _this.withCache(annotate(factory));
321
+ });
322
+ var schema = assignPropsToFn(preparedHistory[latestVersion], {
289
323
  forVersion: function (targetVersion) {
290
324
  if (targetVersion === null || targetVersion === undefined) {
291
- return map(latestFactory);
325
+ return preparedHistory[latestVersion];
292
326
  }
293
- if (targetVersion in history) {
294
- return map(history[targetVersion]);
327
+ if (targetVersion in preparedHistory) {
328
+ return preparedHistory[targetVersion];
295
329
  }
296
- var closestVersion = _this.findClosestVersion(Object.keys(history), targetVersion, VersionedSchemaFactory.compareVersions);
297
- if (closestVersion === undefined || !(closestVersion in history)) {
330
+ var closestVersion = _this.findClosestVersion(Object.keys(preparedHistory), targetVersion, VersionedSchemaFactory.compareVersions);
331
+ if (closestVersion === undefined || !(closestVersion in preparedHistory)) {
298
332
  throw new Error("\u041D\u0435 \u043D\u0430\u0439\u0434\u0435\u043D\u043E \u043F\u043E\u0434\u0445\u043E\u0434\u044F\u0449\u0435\u0439 \u0441\u0445\u0435\u043C\u044B \u0434\u043B\u044F \u0432\u0435\u0440\u0441\u0438\u0438 '".concat(targetVersion, "'"));
299
333
  }
300
- return map(history[closestVersion]);
334
+ return preparedHistory[closestVersion];
301
335
  },
302
336
  });
303
337
  return schema;
@@ -697,12 +731,84 @@ var FormulaNullableSchema = SchemaRegistry.define({
697
731
  },
698
732
  });
699
733
 
734
+ // NOTE: В будущем можно сделать fluent-обёртку для цепочных вызовов:
735
+ // withMetaDecorator(schema).omit({ field: true }).extend({ newField: z.string() })
736
+ // Это позволит избежать вложенных вызовов omitWithMeta/extendWithMeta.
737
+ var PARENT_META_KEY = "parent";
738
+ /**
739
+ * Возвращает родительскую мету схемы, установленную через extendWithMeta / omitWithMeta.
740
+ * Используй для обхода цепочки наследования схем.
741
+ */
742
+ function getParentMeta(meta) {
743
+ return meta[PARENT_META_KEY];
744
+ }
745
+ function inheritMeta(target, source) {
746
+ var _a;
747
+ var sourceMeta = source.meta();
748
+ return sourceMeta !== undefined ? target.meta((_a = {}, _a[PARENT_META_KEY] = sourceMeta, _a)) : target;
749
+ }
750
+ /**
751
+ * Расширяет Zod-схему дополнительными полями, сохраняя цепочку наследования мет.
752
+ *
753
+ * Мета базовой схемы сохраняется как `parent` в мете расширенной схемы — формируя
754
+ * иммутабельный связанный список.
755
+ *
756
+ * Используй вместо `.extend()` при расширении схем, задекларированных через
757
+ * `SchemaRegistry.define`, — это обязательное условие корректной работы миграций.
758
+ *
759
+ * @example
760
+ * // Вместо:
761
+ * DimensionSchema(z).extend({ color: ColorSchema(z) })
762
+ *
763
+ * // Используй:
764
+ * extendWithMeta(DimensionSchema(z), { color: ColorSchema(z) })
765
+ */
766
+ function extendWithMeta(schema, extension) {
767
+ return inheritMeta(schema.extend(extension), schema);
768
+ }
769
+ /**
770
+ * Создаёт Zod-схему с удалёнными полями, сохраняя цепочку наследования мет.
771
+ *
772
+ * Мета базовой схемы сохраняется как `parent` в мете результирующей схемы.
773
+ *
774
+ * Используй вместо `.omit()` при работе со схемами, задекларированными через
775
+ * `SchemaRegistry.define`, — это обязательное условие корректной работы миграций.
776
+ *
777
+ * @example
778
+ * // Вместо:
779
+ * BaseWidgetSettingsSchema(z).omit({ paddings: true })
780
+ *
781
+ * // Используй:
782
+ * omitWithMeta(BaseWidgetSettingsSchema(z), { paddings: true })
783
+ */
784
+ function omitWithMeta(schema, keys) {
785
+ return inheritMeta(schema.omit(keys), schema);
786
+ }
787
+ /**
788
+ * Проверяет, есть ли в цепочке наследования мет узел, удовлетворяющий предикату.
789
+ *
790
+ * Обходит цепочку от текущей меты к корню через ссылки parent, установленные
791
+ * функциями extendWithMeta / omitWithMeta.
792
+ *
793
+ * @example
794
+ * hasInMetaChain(schema.meta(), (meta) => meta.type === "WidgetDimension")
795
+ */
796
+ function hasInMetaChain(meta, predicate) {
797
+ var current = meta;
798
+ while (current !== undefined) {
799
+ if (predicate(current))
800
+ return true;
801
+ current = getParentMeta(current);
802
+ }
803
+ return false;
804
+ }
805
+
700
806
  var WidgetIndicatorSchema = SchemaRegistry.define({
701
807
  key: "WidgetIndicator",
702
808
  latestVersion: "17",
703
809
  history: {
704
810
  "17": function (z) {
705
- return AutoIdentifiedArrayItemSchema.forVersion("17")(z).extend({
811
+ return extendWithMeta(AutoIdentifiedArrayItemSchema.forVersion("17")(z), {
706
812
  name: z.string(),
707
813
  });
708
814
  },
@@ -753,7 +859,7 @@ var WidgetColumnIndicatorSchema = SchemaRegistry.define({
753
859
  latestVersion: "17",
754
860
  history: {
755
861
  "17": function (z) {
756
- return WidgetIndicatorSchema.forVersion("17")(z).extend({
862
+ return extendWithMeta(WidgetIndicatorSchema.forVersion("17")(z), {
757
863
  dbDataType: z.string().optional(),
758
864
  format: FormatSchema.forVersion("17")(z).optional(),
759
865
  formatting: FormattingSchema.forVersion("17")(z).optional(),
@@ -808,7 +914,7 @@ var MeasureValueSchema = SchemaRegistry.define({
808
914
  "17": function (z) {
809
915
  return z.discriminatedUnion("mode", [
810
916
  WidgetIndicatorFormulaValueSchema.forVersion("17")(z),
811
- WidgetIndicatorTemplateValueSchema.forVersion("17")(z).extend({
917
+ extendWithMeta(WidgetIndicatorTemplateValueSchema.forVersion("17")(z), {
812
918
  innerTemplateName: z.enum(exports.EMeasureInnerTemplateNames).optional(),
813
919
  }),
814
920
  ]);
@@ -822,7 +928,7 @@ var DimensionValueSchema = SchemaRegistry.define({
822
928
  "17": function (z) {
823
929
  return z.discriminatedUnion("mode", [
824
930
  WidgetIndicatorFormulaValueSchema.forVersion("17")(z),
825
- WidgetIndicatorTemplateValueSchema.forVersion("17")(z).extend({
931
+ extendWithMeta(WidgetIndicatorTemplateValueSchema.forVersion("17")(z), {
826
932
  innerTemplateName: z.never().optional(),
827
933
  }),
828
934
  ]);
@@ -856,7 +962,7 @@ var WidgetMeasureAggregationValueSchema = SchemaRegistry.define({
856
962
  latestVersion: "17",
857
963
  history: {
858
964
  "17": function (z) {
859
- return WidgetIndicatorAggregationValueSchema.forVersion("17")(z).extend({
965
+ return extendWithMeta(WidgetIndicatorAggregationValueSchema.forVersion("17")(z), {
860
966
  outerAggregation: z.enum(exports.EOuterAggregation),
861
967
  });
862
968
  },
@@ -888,11 +994,11 @@ var WidgetDimensionSchema = SchemaRegistry.define({
888
994
  latestVersion: "17",
889
995
  history: {
890
996
  "17": function (z) {
891
- return WidgetColumnIndicatorSchema.forVersion("17")(z).extend({
997
+ return extendWithMeta(WidgetColumnIndicatorSchema.forVersion("17")(z), {
892
998
  value: z
893
999
  .discriminatedUnion("mode", [
894
1000
  DimensionValueSchema.forVersion("17")(z),
895
- WidgetIndicatorAggregationValueSchema.forVersion("17")(z).extend({
1001
+ extendWithMeta(WidgetIndicatorAggregationValueSchema.forVersion("17")(z), {
896
1002
  innerTemplateName: z.string().optional(),
897
1003
  }),
898
1004
  WidgetIndicatorTimeValueSchema.forVersion("17")(z),
@@ -907,7 +1013,9 @@ var WidgetDimensionInHierarchySchema = SchemaRegistry.define({
907
1013
  key: "WidgetDimensionInHierarchy",
908
1014
  latestVersion: "17",
909
1015
  history: {
910
- "17": function (z) { return WidgetDimensionSchema.forVersion("17")(z).omit({ displayCondition: true }); },
1016
+ "17": function (z) {
1017
+ return omitWithMeta(WidgetDimensionSchema.forVersion("17")(z), { displayCondition: true });
1018
+ },
911
1019
  },
912
1020
  });
913
1021
  var WidgetDimensionHierarchySchema = SchemaRegistry.define({
@@ -915,7 +1023,7 @@ var WidgetDimensionHierarchySchema = SchemaRegistry.define({
915
1023
  latestVersion: "17",
916
1024
  history: {
917
1025
  "17": function (z, dimensionSchema) {
918
- return AutoIdentifiedArrayItemSchema.forVersion("17")(z).extend({
1026
+ return extendWithMeta(AutoIdentifiedArrayItemSchema.forVersion("17")(z), {
919
1027
  name: z.string(),
920
1028
  // Для иерархии является дискриминатором, для него нельзя задавать дефолтное значение.
921
1029
  hierarchyDimensions: z.array(dimensionSchema),
@@ -953,7 +1061,7 @@ var WidgetIndicatorDurationValueSchema = SchemaRegistry.define({
953
1061
  latestVersion: "17",
954
1062
  history: {
955
1063
  "17": function (z) {
956
- return WidgetIndicatorConversionValueSchema.forVersion("17")(z).extend({
1064
+ return extendWithMeta(WidgetIndicatorConversionValueSchema.forVersion("17")(z), {
957
1065
  mode: z.literal(exports.EWidgetIndicatorValueModes.DURATION),
958
1066
  templateName: z.string(),
959
1067
  startEventAppearances: z.enum(exports.EEventAppearances),
@@ -967,7 +1075,7 @@ var WidgetMeasureSchema = SchemaRegistry.define({
967
1075
  latestVersion: "17",
968
1076
  history: {
969
1077
  "17": function (z) {
970
- return WidgetColumnIndicatorSchema.forVersion("17")(z).extend({
1078
+ return extendWithMeta(WidgetColumnIndicatorSchema.forVersion("17")(z), {
971
1079
  value: z
972
1080
  .discriminatedUnion("mode", [
973
1081
  MeasureValueSchema.forVersion("17")(z),
@@ -985,7 +1093,7 @@ var MarkdownMeasureSchema = SchemaRegistry.define({
985
1093
  latestVersion: "17",
986
1094
  history: {
987
1095
  "17": function (z) {
988
- return WidgetMeasureSchema.forVersion("17")(z).extend({
1096
+ return extendWithMeta(WidgetMeasureSchema.forVersion("17")(z), {
989
1097
  displaySign: z.enum(exports.EMarkdownDisplayMode).default(exports.EMarkdownDisplayMode.NONE),
990
1098
  });
991
1099
  },
@@ -996,7 +1104,7 @@ var WidgetSortingIndicatorSchema = SchemaRegistry.define({
996
1104
  latestVersion: "17",
997
1105
  history: {
998
1106
  "17": function (z) {
999
- return WidgetIndicatorSchema.forVersion("17")(z).extend({
1107
+ return extendWithMeta(WidgetIndicatorSchema.forVersion("17")(z), {
1000
1108
  direction: SortDirectionSchema.forVersion("17")(z),
1001
1109
  value: WidgetSortingValueSchema.forVersion("17")(z),
1002
1110
  });
@@ -1027,7 +1135,7 @@ var ProcessIndicatorSchema = SchemaRegistry.define({
1027
1135
  latestVersion: "17",
1028
1136
  history: {
1029
1137
  "17": function (z) {
1030
- return WidgetIndicatorSchema.forVersion("17")(z).extend({
1138
+ return extendWithMeta(WidgetIndicatorSchema.forVersion("17")(z), {
1031
1139
  value: ProcessIndicatorValueSchema.forVersion("17")(z).optional(),
1032
1140
  dbDataType: z.string().optional(),
1033
1141
  format: FormatSchema.forVersion("17")(z).optional(),
@@ -1091,10 +1199,10 @@ var DimensionProcessFilterSchema = SchemaRegistry.define({
1091
1199
  "17": function (z) {
1092
1200
  return z.object({
1093
1201
  value: z.union([
1094
- WidgetIndicatorAggregationValueSchema.forVersion("17")(z).extend({
1202
+ extendWithMeta(WidgetIndicatorAggregationValueSchema.forVersion("17")(z), {
1095
1203
  outerAggregation: z.enum(exports.EOuterAggregation),
1096
1204
  }),
1097
- WidgetIndicatorAggregationValueSchema.forVersion("17")(z).extend({
1205
+ extendWithMeta(WidgetIndicatorAggregationValueSchema.forVersion("17")(z), {
1098
1206
  innerTemplateName: z.string().optional(),
1099
1207
  }),
1100
1208
  WidgetIndicatorTimeValueSchema.forVersion("17")(z),
@@ -1131,7 +1239,7 @@ var ActionOnClickParameterCommonSchema = SchemaRegistry.define({
1131
1239
  latestVersion: "17",
1132
1240
  history: {
1133
1241
  "17": function (z) {
1134
- return AutoIdentifiedArrayItemSchema.forVersion("17")(z).extend({
1242
+ return extendWithMeta(AutoIdentifiedArrayItemSchema.forVersion("17")(z), {
1135
1243
  name: z.string(),
1136
1244
  });
1137
1245
  },
@@ -1322,7 +1430,7 @@ var ActionCommonSchema = SchemaRegistry.define({
1322
1430
  latestVersion: "17",
1323
1431
  history: {
1324
1432
  "17": function (z) {
1325
- return AutoIdentifiedArrayItemSchema.forVersion("17")(z).extend({
1433
+ return extendWithMeta(AutoIdentifiedArrayItemSchema.forVersion("17")(z), {
1326
1434
  name: z.string(),
1327
1435
  });
1328
1436
  },
@@ -1333,7 +1441,7 @@ var ActionDrillDownSchema = SchemaRegistry.define({
1333
1441
  latestVersion: "17",
1334
1442
  history: {
1335
1443
  "17": function (z) {
1336
- return ActionCommonSchema.forVersion("17")(z).extend({
1444
+ return extendWithMeta(ActionCommonSchema.forVersion("17")(z), {
1337
1445
  type: z.literal(exports.EActionTypes.DRILL_DOWN),
1338
1446
  variables: z.array(ActionOnClickParameterSchema.forVersion("17")(z)).default([]),
1339
1447
  });
@@ -1345,7 +1453,7 @@ var ActionGoToURLSchema = SchemaRegistry.define({
1345
1453
  latestVersion: "17",
1346
1454
  history: {
1347
1455
  "17": function (z) {
1348
- return ActionCommonSchema.forVersion("17")(z).extend({
1456
+ return extendWithMeta(ActionCommonSchema.forVersion("17")(z), {
1349
1457
  type: z.literal(exports.EActionTypes.OPEN_URL),
1350
1458
  url: z.string(),
1351
1459
  newWindow: z.boolean().default(true),
@@ -1380,7 +1488,7 @@ var ActionRunScriptSchema = SchemaRegistry.define({
1380
1488
  latestVersion: "17",
1381
1489
  history: {
1382
1490
  "17": function (z) {
1383
- return ActionCommonSchema.forVersion("17")(z).extend({
1491
+ return extendWithMeta(ActionCommonSchema.forVersion("17")(z), {
1384
1492
  type: z.literal(exports.EActionTypes.EXECUTE_SCRIPT),
1385
1493
  parameters: z.array(ActionOnClickParameterSchema.forVersion("17")(z)).default([]),
1386
1494
  scriptKey: z.string(),
@@ -1399,7 +1507,7 @@ var ActionUpdateVariableSchema = SchemaRegistry.define({
1399
1507
  latestVersion: "17",
1400
1508
  history: {
1401
1509
  "17": function (z) {
1402
- return ActionCommonSchema.forVersion("17")(z).extend({
1510
+ return extendWithMeta(ActionCommonSchema.forVersion("17")(z), {
1403
1511
  type: z.literal(exports.EActionTypes.UPDATE_VARIABLE),
1404
1512
  variables: z.array(ActionOnClickParameterSchema.forVersion("17")(z)).default([]),
1405
1513
  });
@@ -1440,7 +1548,7 @@ var ActionOpenViewCommonSchema = SchemaRegistry.define({
1440
1548
  latestVersion: "17",
1441
1549
  history: {
1442
1550
  "17": function (z) {
1443
- return ActionCommonSchema.forVersion("17")(z).extend({
1551
+ return extendWithMeta(ActionCommonSchema.forVersion("17")(z), {
1444
1552
  type: z.literal(exports.EActionTypes.OPEN_VIEW),
1445
1553
  variables: z.array(ActionOnClickParameterSchema.forVersion("17")(z)).default([]),
1446
1554
  });
@@ -1453,18 +1561,18 @@ var ActionOpenViewSchema = SchemaRegistry.define({
1453
1561
  history: {
1454
1562
  "17": function (z) {
1455
1563
  return z.intersection(z.discriminatedUnion("mode", [
1456
- ActionOpenViewCommonSchema.forVersion("17")(z).extend({
1564
+ extendWithMeta(ActionOpenViewCommonSchema.forVersion("17")(z), {
1457
1565
  mode: z.literal(exports.EViewMode.GENERATED_BY_SCRIPT),
1458
1566
  scriptKey: z.string().optional(),
1459
1567
  parameters: z.array(ActionOnClickParameterSchema.forVersion("17")(z)).default([]),
1460
1568
  displayName: z.string().default(""),
1461
1569
  }),
1462
- ActionOpenViewCommonSchema.forVersion("17")(z).extend({
1570
+ extendWithMeta(ActionOpenViewCommonSchema.forVersion("17")(z), {
1463
1571
  mode: z.literal(exports.EViewMode.EXISTED_VIEW),
1464
1572
  viewKey: z.string().optional(),
1465
1573
  parameters: z.array(ActionOnClickParameterSchema.forVersion("17")(z)).default([]),
1466
1574
  }),
1467
- ActionOpenViewCommonSchema.forVersion("17")(z).extend({
1575
+ extendWithMeta(ActionOpenViewCommonSchema.forVersion("17")(z), {
1468
1576
  mode: z.literal(exports.EViewMode.EMPTY),
1469
1577
  placeholderName: z.string().optional(),
1470
1578
  openIn: z.literal(exports.EViewOpenIn.PLACEHOLDER),
@@ -1493,7 +1601,7 @@ var WidgetActionParameterCommonSchema = SchemaRegistry.define({
1493
1601
  latestVersion: "17",
1494
1602
  history: {
1495
1603
  "17": function (z) {
1496
- return AutoIdentifiedArrayItemSchema.forVersion("17")(z).extend({
1604
+ return extendWithMeta(AutoIdentifiedArrayItemSchema.forVersion("17")(z), {
1497
1605
  name: z.string(),
1498
1606
  displayName: z.string().default(""),
1499
1607
  isHidden: z.boolean().default(false),
@@ -1524,7 +1632,7 @@ var WidgetActionSchema = SchemaRegistry.define({
1524
1632
  latestVersion: "17",
1525
1633
  history: {
1526
1634
  "17": function (z) {
1527
- return ActionCommonSchema.forVersion("17")(z).extend({
1635
+ return extendWithMeta(ActionCommonSchema.forVersion("17")(z), {
1528
1636
  parameters: z.array(WidgetActionParameterSchema.forVersion("17")(z)).default([]),
1529
1637
  type: z.literal(exports.EActionTypes.EXECUTE_SCRIPT),
1530
1638
  scriptKey: z.string(),
@@ -1544,7 +1652,7 @@ var ViewActionParameterSchema = SchemaRegistry.define({
1544
1652
  latestVersion: "17",
1545
1653
  history: {
1546
1654
  "17": function (z) {
1547
- return z.intersection(AutoIdentifiedArrayItemSchema.forVersion("17")(z).extend({ name: z.string() }), z.discriminatedUnion("inputMethod", [
1655
+ return z.intersection(extendWithMeta(AutoIdentifiedArrayItemSchema.forVersion("17")(z), { name: z.string() }), z.discriminatedUnion("inputMethod", [
1548
1656
  ParameterFromAggregationSchema.forVersion("17")(z),
1549
1657
  ParameterFromVariableSchema.forVersion("17")(z),
1550
1658
  ]));
@@ -1556,7 +1664,7 @@ var ViewActionSchema = SchemaRegistry.define({
1556
1664
  latestVersion: "17",
1557
1665
  history: {
1558
1666
  "17": function (z) {
1559
- return AutoIdentifiedArrayItemSchema.forVersion("17")(z).extend({
1667
+ return extendWithMeta(AutoIdentifiedArrayItemSchema.forVersion("17")(z), {
1560
1668
  name: z.string(),
1561
1669
  buttonType: z.enum(exports.EActionButtonsTypes).default(exports.EActionButtonsTypes.BASE),
1562
1670
  type: z.literal(exports.EActionTypes.EXECUTE_SCRIPT).default(exports.EActionTypes.EXECUTE_SCRIPT),
@@ -1587,7 +1695,7 @@ var ActionButtonSchema = SchemaRegistry.define({
1587
1695
  latestVersion: "17",
1588
1696
  history: {
1589
1697
  "17": function (z) {
1590
- return AutoIdentifiedArrayItemSchema.forVersion("17")(z).extend({
1698
+ return extendWithMeta(AutoIdentifiedArrayItemSchema.forVersion("17")(z), {
1591
1699
  name: z.string(),
1592
1700
  onClick: z.array(WidgetActionSchema.forVersion("17")(z)).default([]),
1593
1701
  buttonType: z.enum(exports.EActionButtonsTypes).default(exports.EActionButtonsTypes.BASE),
@@ -3610,6 +3718,7 @@ exports.durationTemplates = durationTemplates;
3610
3718
  exports.escapeCurlyBracketLinkName = escapeCurlyBracketLinkName;
3611
3719
  exports.escapeDoubleQuoteLinkName = escapeDoubleQuoteLinkName;
3612
3720
  exports.eventMeasureTemplateFormulas = eventMeasureTemplateFormulas;
3721
+ exports.extendWithMeta = extendWithMeta;
3613
3722
  exports.fillTemplateSql = fillTemplateSql;
3614
3723
  exports.formulaFilterMethods = formulaFilterMethods;
3615
3724
  exports.generateColumnFormula = generateColumnFormula;
@@ -3619,9 +3728,11 @@ exports.getDimensionFormula = getDimensionFormula;
3619
3728
  exports.getDisplayConditionFormula = getDisplayConditionFormula;
3620
3729
  exports.getEventMeasureFormula = getEventMeasureFormula;
3621
3730
  exports.getMeasureFormula = getMeasureFormula;
3731
+ exports.getParentMeta = getParentMeta;
3622
3732
  exports.getProcessDimensionValueFormula = getProcessDimensionValueFormula;
3623
3733
  exports.getRuleColor = getRuleColor;
3624
3734
  exports.getTransitionMeasureFormula = getTransitionMeasureFormula;
3735
+ exports.hasInMetaChain = hasInMetaChain;
3625
3736
  exports.hexToRgb = hexToRgb;
3626
3737
  exports.inheritDisplayConditionFromHierarchy = inheritDisplayConditionFromHierarchy;
3627
3738
  exports.interpolateHexColor = interpolateHexColor;
@@ -3639,6 +3750,7 @@ exports.mapSortingToInputs = mapSortingToInputs;
3639
3750
  exports.mapTransitionMeasuresToInputs = mapTransitionMeasuresToInputs;
3640
3751
  exports.measureInnerTemplateFormulas = measureInnerTemplateFormulas;
3641
3752
  exports.measureTemplateFormulas = measureTemplateFormulas;
3753
+ exports.omitWithMeta = omitWithMeta;
3642
3754
  exports.parseClickHouseType = parseClickHouseType;
3643
3755
  exports.parseIndicatorLink = parseIndicatorLink;
3644
3756
  exports.prepareConversionParams = prepareConversionParams;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@infomaximum/widget-sdk",
3
- "version": "7.0.0-16",
3
+ "version": "7.0.0-18",
4
4
  "main": "./dist/index.js",
5
5
  "module": "./dist/index.esm.js",
6
6
  "types": "./dist/index.d.ts",
@@ -12,7 +12,7 @@
12
12
  "sideEffects": false,
13
13
  "scripts": {
14
14
  "build": "rollup -c",
15
- "lint": "tsc --noEmit",
15
+ "lint": "tsc --noEmit && eslint src --ext .ts",
16
16
  "release": "standard-version",
17
17
  "release:rc": "standard-version -p",
18
18
  "release:prev": "node ./scripts/re-release.mjs",
@@ -37,6 +37,9 @@
37
37
  "@rollup/plugin-typescript": "11.1.5",
38
38
  "@types/jest": "^29.5.14",
39
39
  "@types/semver": "^7.7.0",
40
+ "@typescript-eslint/eslint-plugin": "^8",
41
+ "@typescript-eslint/parser": "^8",
42
+ "eslint": "^8",
40
43
  "core-js": "^3.38.0",
41
44
  "jest": "^29.7.0",
42
45
  "prettier": "3.2.5",