From 4c3c9f16a025dbd924add251a2bed982e6f2794e Mon Sep 17 00:00:00 2001 From: griest024 Date: Wed, 16 Oct 2024 12:13:43 -0400 Subject: [PATCH] feat(all): use functions for providing configs (#3283) BREAKING CHANGE: `SEARCH_FEDERATED_CONFIG_DEFAULT` -> `DAFF_SEARCH_FEDERATED_CONFIG_DEFAULT`, `SEARCH_FEDERATED_CONFIG_TOKEN` -> `DAFF_SEARCH_FEDERATED_CONFIG_TOKEN` --- .../magento/src/category-driver.module.ts | 16 +++---------- .../src/interfaces/config.interface.ts | 2 +- .../magento/src/navigation-driver.module.ts | 10 ++------ .../src/interfaces/config.interface.ts | 2 +- .../magento/src/product-driver.module.ts | 10 ++------ .../driver/federated/src/config/default.ts | 2 +- .../driver/federated/src/config/interface.ts | 10 ++++---- .../driver/federated/src/config/public_api.ts | 7 ++---- .../federated/src/search-driver.module.ts | 24 +++++-------------- .../driver/federated/src/search.service.ts | 4 ++-- 10 files changed, 25 insertions(+), 62 deletions(-) diff --git a/libs/category/driver/magento/src/category-driver.module.ts b/libs/category/driver/magento/src/category-driver.module.ts index 37d49c60c4..8d591a0113 100644 --- a/libs/category/driver/magento/src/category-driver.module.ts +++ b/libs/category/driver/magento/src/category-driver.module.ts @@ -6,17 +6,13 @@ import { import { provideDaffCategoryDriver } from '@daffodil/category/driver'; import { DAFF_MAGENTO_CACHEABLE_OPERATIONS } from '@daffodil/driver/magento'; -import { - provideDaffProductMagentoExtraProductPreviewFragments, - DAFF_MAGENTO_GET_FILTER_TYPES_QUERY_NAME, - magentoProductPreviewFragment, -} from '@daffodil/product/driver/magento'; +import { DAFF_MAGENTO_GET_FILTER_TYPES_QUERY_NAME } from '@daffodil/product/driver/magento'; import { DaffMagentoCategoryService } from './category.service'; import { MAGENTO_CATEGORY_CONFIG_DEFAULT } from './config/default'; import { DaffCategoryMagentoDriverConfig, - MAGENTO_CATEGORY_CONFIG_TOKEN, + provideMagentoCategoryConfig, } from './interfaces/public_api'; import { DAFF_MAGENTO_GET_CATEGORY_AND_PRODUCTS_QUERY_NAME, @@ -61,13 +57,7 @@ export class DaffCategoryMagentoDriverModule { useValue: DAFF_MAGENTO_RESOLVE_CATEGORY_URL_QUERY_NAME, multi: true, }, - { - provide: MAGENTO_CATEGORY_CONFIG_TOKEN, - useValue: { - ...MAGENTO_CATEGORY_CONFIG_DEFAULT, - ...config, - }, - }, + provideMagentoCategoryConfig(config), ], }; } diff --git a/libs/category/driver/magento/src/interfaces/config.interface.ts b/libs/category/driver/magento/src/interfaces/config.interface.ts index ef23a469dd..60ab027fc0 100644 --- a/libs/category/driver/magento/src/interfaces/config.interface.ts +++ b/libs/category/driver/magento/src/interfaces/config.interface.ts @@ -8,7 +8,7 @@ export const { * Mandatory for the Magento driver. */ token: MAGENTO_CATEGORY_CONFIG_TOKEN, - provider: provideDaffAnalyticsConfig, + provider: provideMagentoCategoryConfig, } = createConfigInjectionToken( MAGENTO_CATEGORY_CONFIG_DEFAULT, 'MAGENTO_CATEGORY_CONFIG_TOKEN', diff --git a/libs/navigation/driver/magento/src/navigation-driver.module.ts b/libs/navigation/driver/magento/src/navigation-driver.module.ts index 006c09c5ed..c6097a51f9 100644 --- a/libs/navigation/driver/magento/src/navigation-driver.module.ts +++ b/libs/navigation/driver/magento/src/navigation-driver.module.ts @@ -13,7 +13,7 @@ import { import { MagentoNavigationDriverConfig, MAGENTO_NAVIGATION_DRIVER_CONFIG_DEFAULT, - MAGENTO_NAVIGATION_DRIVER_CONFIG, + provideMagentoNavigationDriverConfig, } from './config/public_api'; import { DaffMagentoNavigationService } from './navigation.service'; import { DAFF_MAGENTO_GET_CATEGORY_TREE_QUERY_NAME } from './queries/get-category-tree'; @@ -34,13 +34,7 @@ export class DaffNavigationMagentoDriverModule { provide: DaffNavigationTransformer, useExisting: DaffMagentoNavigationTransformerService, }, - { - provide: MAGENTO_NAVIGATION_DRIVER_CONFIG, - useValue: { - ...MAGENTO_NAVIGATION_DRIVER_CONFIG_DEFAULT, - ...config, - }, - }, + provideMagentoNavigationDriverConfig(config), { provide: DAFF_MAGENTO_CACHEABLE_OPERATIONS, useValue: DAFF_MAGENTO_GET_CATEGORY_TREE_QUERY_NAME, diff --git a/libs/product/driver/magento/src/interfaces/config.interface.ts b/libs/product/driver/magento/src/interfaces/config.interface.ts index d2e8f796a9..e639817a58 100644 --- a/libs/product/driver/magento/src/interfaces/config.interface.ts +++ b/libs/product/driver/magento/src/interfaces/config.interface.ts @@ -8,7 +8,7 @@ export const { * Mandatory for the Magento driver. */ token: MAGENTO_PRODUCT_CONFIG_TOKEN, - provider: provideDaffProductMagentoConfig, + provider: provideMagentoProductConfig, } = createConfigInjectionToken( MAGENTO_PRODUCT_CONFIG_DEFAULT, 'MAGENTO_PRODUCT_CONFIG_TOKEN', diff --git a/libs/product/driver/magento/src/product-driver.module.ts b/libs/product/driver/magento/src/product-driver.module.ts index 3b50b9b41f..0a5dae3ada 100644 --- a/libs/product/driver/magento/src/product-driver.module.ts +++ b/libs/product/driver/magento/src/product-driver.module.ts @@ -10,7 +10,7 @@ import { provideDaffProductDriver } from '@daffodil/product/driver'; import { MAGENTO_PRODUCT_CONFIG_DEFAULT } from './config/public_api'; import { DaffProductMagentoDriverConfig, - MAGENTO_PRODUCT_CONFIG_TOKEN, + provideMagentoProductConfig, } from './interfaces/public_api'; import { DaffMagentoProductService } from './product.service'; import { DAFF_MAGENTO_GET_ALL_PRODUCTS_QUERY_NAME } from './queries/get-all-products'; @@ -47,13 +47,7 @@ export class DaffProductMagentoDriverModule { useValue: DAFF_MAGENTO_GET_A_PRODUCT_BY_URL_QUERY_NAME, multi: true, }, - { - provide: MAGENTO_PRODUCT_CONFIG_TOKEN, - useValue: { - ...MAGENTO_PRODUCT_CONFIG_DEFAULT, - ...config, - }, - }, + provideMagentoProductConfig(config), ], }; } diff --git a/libs/search/driver/federated/src/config/default.ts b/libs/search/driver/federated/src/config/default.ts index baed65969b..d530d2a850 100644 --- a/libs/search/driver/federated/src/config/default.ts +++ b/libs/search/driver/federated/src/config/default.ts @@ -3,4 +3,4 @@ import { DaffSearchFederatedDriverConfig } from './interface'; /** * The default configuration for the {@link DaffSearchFederatedDriverConfig}. */ -export const SEARCH_FEDERATED_CONFIG_DEFAULT: DaffSearchFederatedDriverConfig = {}; +export const DAFF_SEARCH_FEDERATED_CONFIG_DEFAULT: DaffSearchFederatedDriverConfig = {}; diff --git a/libs/search/driver/federated/src/config/interface.ts b/libs/search/driver/federated/src/config/interface.ts index b48e16f39d..444123df0c 100644 --- a/libs/search/driver/federated/src/config/interface.ts +++ b/libs/search/driver/federated/src/config/interface.ts @@ -1,17 +1,17 @@ import { createConfigInjectionToken } from '@daffodil/core'; -import { SEARCH_FEDERATED_CONFIG_DEFAULT } from './default'; +import { DAFF_SEARCH_FEDERATED_CONFIG_DEFAULT } from './default'; export const { /** * The token used to provide @daffodil/search/driver/federated config data. * Mandatory for the Magento driver. */ - token: SEARCH_FEDERATED_CONFIG_TOKEN, - provider: provideDaffAnalyticsConfig, + token: DAFF_SEARCH_FEDERATED_CONFIG_TOKEN, + provider: provideDaffSearchFederatedConfig, } = createConfigInjectionToken( - SEARCH_FEDERATED_CONFIG_DEFAULT, - 'SEARCH_FEDERATED_CONFIG_TOKEN', + DAFF_SEARCH_FEDERATED_CONFIG_DEFAULT, + 'DAFF_SEARCH_FEDERATED_CONFIG_TOKEN', ); /** diff --git a/libs/search/driver/federated/src/config/public_api.ts b/libs/search/driver/federated/src/config/public_api.ts index ec44b8e1ad..a0e76624fc 100644 --- a/libs/search/driver/federated/src/config/public_api.ts +++ b/libs/search/driver/federated/src/config/public_api.ts @@ -1,5 +1,2 @@ -export { SEARCH_FEDERATED_CONFIG_DEFAULT } from './default'; -export { - SEARCH_FEDERATED_CONFIG_TOKEN, - DaffSearchFederatedDriverConfig, -} from './interface'; +export { DAFF_SEARCH_FEDERATED_CONFIG_DEFAULT } from './default'; +export * from './interface'; diff --git a/libs/search/driver/federated/src/search-driver.module.ts b/libs/search/driver/federated/src/search-driver.module.ts index 877070c418..381e4d32dc 100644 --- a/libs/search/driver/federated/src/search-driver.module.ts +++ b/libs/search/driver/federated/src/search-driver.module.ts @@ -11,8 +11,8 @@ import { import { DaffSearchFederatedDriverConfig, - SEARCH_FEDERATED_CONFIG_DEFAULT, - SEARCH_FEDERATED_CONFIG_TOKEN, + DAFF_SEARCH_FEDERATED_CONFIG_DEFAULT, + provideDaffSearchFederatedConfig, } from './config/public_api'; import { DaffSearchFederatedDriver } from './search.service'; @@ -25,23 +25,17 @@ import { DaffSearchFederatedDriver } from './search.service'; ], }) export class DaffSearchFederatedDriverModule { - static forRoot(config: DaffSearchFederatedDriverConfig = SEARCH_FEDERATED_CONFIG_DEFAULT): ModuleWithProviders { + static forRoot(config: DaffSearchFederatedDriverConfig = DAFF_SEARCH_FEDERATED_CONFIG_DEFAULT): ModuleWithProviders { return { ngModule: DaffSearchFederatedDriverModule, providers: [ provideDaffSearchDriver(DaffSearchFederatedDriver), - { - provide: SEARCH_FEDERATED_CONFIG_TOKEN, - useValue: { - ...SEARCH_FEDERATED_CONFIG_DEFAULT, - ...config, - }, - }, + provideDaffSearchFederatedConfig(config), ], }; } - static forFeature(config: DaffSearchFederatedDriverConfig = SEARCH_FEDERATED_CONFIG_DEFAULT): ModuleWithProviders { + static forFeature(config: DaffSearchFederatedDriverConfig = DAFF_SEARCH_FEDERATED_CONFIG_DEFAULT): ModuleWithProviders { return { ngModule: DaffSearchFederatedDriverModule, providers: [ @@ -49,13 +43,7 @@ export class DaffSearchFederatedDriverModule { provide: DaffSearchDriver, useClass: DaffSearchFederatedDriver, }, - { - provide: SEARCH_FEDERATED_CONFIG_TOKEN, - useValue: { - ...SEARCH_FEDERATED_CONFIG_DEFAULT, - ...config, - }, - }, + provideDaffSearchFederatedConfig(config), ], }; } diff --git a/libs/search/driver/federated/src/search.service.ts b/libs/search/driver/federated/src/search.service.ts index 7062e7ae4b..1d75d58f60 100644 --- a/libs/search/driver/federated/src/search.service.ts +++ b/libs/search/driver/federated/src/search.service.ts @@ -18,7 +18,7 @@ import { import { DaffSearchFederatedDriverConfig, - SEARCH_FEDERATED_CONFIG_TOKEN, + DAFF_SEARCH_FEDERATED_CONFIG_TOKEN, } from './config/public_api'; import { DAFF_SEARCH_FEDERATED_DRIVERS } from './injection-tokens/drivers.token'; @@ -33,7 +33,7 @@ import { DAFF_SEARCH_FEDERATED_DRIVERS } from './injection-tokens/drivers.token' export class DaffSearchFederatedDriver implements DaffSearchDriverInterface { constructor( @Inject(DAFF_SEARCH_FEDERATED_DRIVERS) private drivers: DaffSearchDriverKindedInterface[], - @Inject(SEARCH_FEDERATED_CONFIG_TOKEN) private config: DaffSearchFederatedDriverConfig, + @Inject(DAFF_SEARCH_FEDERATED_CONFIG_TOKEN) private config: DaffSearchFederatedDriverConfig, ) {} search(query: string, options: DaffSearchDriverOptions = {}): Observable {