From 0f9560eac42e810cfac96c11b204d5ca06a6f08a Mon Sep 17 00:00:00 2001 From: matthieu-crouzet Date: Tue, 13 Aug 2024 15:16:49 +0200 Subject: [PATCH] feat(#1693): create interface itemidentifier --- .../helpers/component/component-config.extractor.ts | 12 ++++++------ .../@o3r/components/src/core/component.output.ts | 4 ++-- packages/@o3r/core/src/core/interfaces/index.ts | 1 + .../core/src/core/interfaces/item-identifier.ts | 13 +++++++++++++ .../design-token-specification.interface.ts | 9 +++------ .../rules-engine/src/engine/engine.interface.ts | 6 +++--- packages/@o3r/rules-engine/src/engine/structure.ts | 6 +++--- packages/@o3r/styling/src/core/styles.interface.ts | 4 +++- 8 files changed, 34 insertions(+), 21 deletions(-) create mode 100644 packages/@o3r/core/src/core/interfaces/item-identifier.ts diff --git a/packages/@o3r/components/builders/component-extractor/helpers/component/component-config.extractor.ts b/packages/@o3r/components/builders/component-extractor/helpers/component/component-config.extractor.ts index 590f204d30..70e0d7c270 100644 --- a/packages/@o3r/components/builders/component-extractor/helpers/component/component-config.extractor.ts +++ b/packages/@o3r/components/builders/component-extractor/helpers/component/component-config.extractor.ts @@ -1,6 +1,6 @@ import { logging } from '@angular-devkit/core'; import type { ConfigProperty, ConfigPropertyTypes, ConfigType, NestedConfiguration } from '@o3r/components'; -import { CategoryDescription } from '@o3r/core'; +import type { CategoryDescription, ItemIdentifier } from '@o3r/core'; import { ConfigDocParser } from '@o3r/extractors'; import { O3rCliError } from '@o3r/schematics'; import { readFileSync } from 'node:fs'; @@ -63,7 +63,7 @@ export class ComponentConfigExtractor { public readonly DEFAULT_UNKNOWN_TYPE = 'unknown'; /** Parser of configuration doc */ - private configDocParser: ConfigDocParser; + private readonly configDocParser: ConfigDocParser; /** * @param libraryName @@ -75,10 +75,10 @@ export class ComponentConfigExtractor { * @param libraries */ constructor( - private libraryName: string, - private strictMode: boolean, + private readonly libraryName: string, + private readonly strictMode: boolean, public source: ts.SourceFile, - private logger: logging.LoggerApi, + private readonly logger: logging.LoggerApi, public filePath: string, public checker: ts.TypeChecker, public libraries: string[] = [] @@ -129,7 +129,7 @@ export class ComponentConfigExtractor { * @param source */ private getTypeFromNode(node: ts.Node | undefined, configurationWrapper?: ConfigurationInformationWrapper, source: ts.SourceFile = this.source): - {type: ConfigPropertyTypes; ref?: {library: string; name: string}; choices?: string[]} { + {type: ConfigPropertyTypes; ref?: ItemIdentifier; choices?: string[]} { const nestedConfiguration = configurationWrapper?.nestedConfiguration; const enumTypesAlias = configurationWrapper?.unionTypeStringLiteral; if (!node) { diff --git a/packages/@o3r/components/src/core/component.output.ts b/packages/@o3r/components/src/core/component.output.ts index cd7db33b91..f2a04b3165 100644 --- a/packages/@o3r/components/src/core/component.output.ts +++ b/packages/@o3r/components/src/core/component.output.ts @@ -1,4 +1,4 @@ -import type { CategoryDescription, ConfigPropertyWidget, Output } from '@o3r/core'; +import type { CategoryDescription, ConfigPropertyWidget, ItemIdentifier, Output } from '@o3r/core'; /** Types of components config */ export type ConfigType = 'Block' | 'Page' | 'AppRuntimeConfiguration' | 'AppBuildConfiguration' | 'ExposedComponent'; @@ -92,7 +92,7 @@ export interface ConfigProperty { /** Label to be used in the CMS for this config */ label: string; /** Reference to the nested configuration if applicable */ - reference?: { library: string; name: string }; + reference?: ItemIdentifier; /** List of possible value options */ choices?: string[]; /** The category of the config property */ diff --git a/packages/@o3r/core/src/core/interfaces/index.ts b/packages/@o3r/core/src/core/interfaces/index.ts index 7f3a8a8257..ab168319d9 100644 --- a/packages/@o3r/core/src/core/interfaces/index.ts +++ b/packages/@o3r/core/src/core/interfaces/index.ts @@ -1,3 +1,4 @@ export * from './configuration'; export * from './context'; +export * from './item-identifier'; export * from './translation'; diff --git a/packages/@o3r/core/src/core/interfaces/item-identifier.ts b/packages/@o3r/core/src/core/interfaces/item-identifier.ts new file mode 100644 index 0000000000..028b9ccc2b --- /dev/null +++ b/packages/@o3r/core/src/core/interfaces/item-identifier.ts @@ -0,0 +1,13 @@ +/** + * Unique identifier of an item in the extracted metadata + */ +export interface ItemIdentifier { + /** + * Name of the library where the item is originally from + */ + library: string; + /** + * Name of the item + */ + name: string; +} diff --git a/packages/@o3r/design/src/core/design-token/design-token-specification.interface.ts b/packages/@o3r/design/src/core/design-token/design-token-specification.interface.ts index 93d9a8c0ae..871de71d19 100644 --- a/packages/@o3r/design/src/core/design-token/design-token-specification.interface.ts +++ b/packages/@o3r/design/src/core/design-token/design-token-specification.interface.ts @@ -1,3 +1,5 @@ +import type { ItemIdentifier } from '@o3r/core'; + /** Metadata information added in the design token extension for Metadata extraction */ export interface DesignTokenMetadata { tags?: string[]; @@ -6,12 +8,7 @@ export interface DesignTokenMetadata { /** Name of a group of variables */ category?: string; /** Component reference if the variable is linked to one */ - component?: { - /** Name of the component */ - name: string; - /** Name of the library containing the component */ - library: string; - }; + component?: ItemIdentifier; } /** Design Token Group Extension fields supported by the default renderer */ diff --git a/packages/@o3r/rules-engine/src/engine/engine.interface.ts b/packages/@o3r/rules-engine/src/engine/engine.interface.ts index 70c41da476..442cd98840 100644 --- a/packages/@o3r/rules-engine/src/engine/engine.interface.ts +++ b/packages/@o3r/rules-engine/src/engine/engine.interface.ts @@ -1,4 +1,4 @@ -import type { Logger } from '@o3r/core'; +import type { ItemIdentifier, Logger } from '@o3r/core'; import { BehaviorSubject, Observable } from 'rxjs'; import type { EngineDebugger } from './debug/engine.debug'; import type { Fact, Facts } from './fact'; @@ -79,12 +79,12 @@ export interface EngineRuleset { * 'or' condition: If at least one component has subscribed, the ruleset will become active. * If present, the {@link linkedComponent} property will not be taken into consideration */ - linkedComponents?: {or: { library: string; name: string }[]}; + linkedComponents?: {or: ItemIdentifier[]}; /** * Component linked to the ruleset, if set it will disable the ruleset execution per default, waiting to a subscription * @deprecated It will be removed in v12, use {@link linkedComponents} instead */ - linkedComponent?: { library: string; name: string }; + linkedComponent?: ItemIdentifier; /** Unique id of the ruleset*/ id: string; /** Stores the result of each rules from the ruleset */ diff --git a/packages/@o3r/rules-engine/src/engine/structure.ts b/packages/@o3r/rules-engine/src/engine/structure.ts index edbf0499e1..18490aab7c 100644 --- a/packages/@o3r/rules-engine/src/engine/structure.ts +++ b/packages/@o3r/rules-engine/src/engine/structure.ts @@ -1,4 +1,4 @@ -import type { RulesEngineAction } from '@o3r/core'; +import type { ItemIdentifier, RulesEngineAction } from '@o3r/core'; export type NativeTypes = string | boolean | number; /** Generic operand */ @@ -141,10 +141,10 @@ export interface Ruleset { * 'or' condition: If at least one component has subscribed, the ruleset will become active. * If provided, the {@link linkedComponent} property will not be taken into consideration */ - linkedComponents?: {or: {library: string; name: string}[]}; + linkedComponents?: {or: ItemIdentifier[]}; /** * Component linked to the ruleset, if set it will disable the ruleset execution per default, waiting to a subscription * @deprecated It will be removed in v12, use {@link linkedComponents} instead */ - linkedComponent?: {library: string; name: string}; + linkedComponent?: ItemIdentifier; } diff --git a/packages/@o3r/styling/src/core/styles.interface.ts b/packages/@o3r/styling/src/core/styles.interface.ts index f4cdb3276a..e1fac63f6d 100644 --- a/packages/@o3r/styling/src/core/styles.interface.ts +++ b/packages/@o3r/styling/src/core/styles.interface.ts @@ -1,3 +1,5 @@ +import type { ItemIdentifier } from '@o3r/core'; + export type CssVariableType = 'string' | 'color'; /** Metadata for a CSS Variable */ @@ -19,7 +21,7 @@ export interface CssVariable { /** Name of a group of variables */ category?: string; /** component reference if the variable is linked to one */ - component?: { library: string; name: string }; + component?: ItemIdentifier; } /** Style Metadata map */