diff --git a/libraries/botbuilder-dialogs-adaptive-teams/tests/actionTests.test.ts b/libraries/botbuilder-dialogs-adaptive-teams/tests/actionTests.test.ts index bf733dee1e..e8b58f7221 100644 --- a/libraries/botbuilder-dialogs-adaptive-teams/tests/actionTests.test.ts +++ b/libraries/botbuilder-dialogs-adaptive-teams/tests/actionTests.test.ts @@ -8,7 +8,7 @@ import { AdaptiveTeamsBotComponent } from '../src/adaptiveTeamsBotComponent'; import { AdaptiveTestBotComponent, TestUtils } from 'botbuilder-dialogs-adaptive-testing'; import { ConnectorClient, MicrosoftAppCredentials } from 'botframework-connector'; import { ComponentDeclarativeTypes, ResourceExplorer } from 'botbuilder-dialogs-declarative'; -import { Configuration, ServiceCollection } from 'botbuilder-runtime-core'; +import { ServiceCollection, noOpConfiguration } from 'botbuilder-runtime-core'; import { jwt } from 'botbuilder-test-utils'; import { ok } from 'assert'; @@ -125,16 +125,9 @@ describe('Actions', function () { declarativeTypes: [], }); - const configuration: Configuration = { - get(_path) { - return undefined; - }, - set(_path, _value) {}, - }; - - new AdaptiveBotComponent().configureServices(services, configuration); - new AdaptiveTeamsBotComponent().configureServices(services, configuration); - new AdaptiveTestBotComponent().configureServices(services, configuration); + new AdaptiveBotComponent().configureServices(services, noOpConfiguration); + new AdaptiveTeamsBotComponent().configureServices(services, noOpConfiguration); + new AdaptiveTestBotComponent().configureServices(services, noOpConfiguration); const declarativeTypes = services.mustMakeInstance('declarativeTypes'); diff --git a/libraries/botbuilder-dialogs-adaptive-teams/tests/conditionalTests.test.ts b/libraries/botbuilder-dialogs-adaptive-teams/tests/conditionalTests.test.ts index c871643775..1c61c6cbcc 100644 --- a/libraries/botbuilder-dialogs-adaptive-teams/tests/conditionalTests.test.ts +++ b/libraries/botbuilder-dialogs-adaptive-teams/tests/conditionalTests.test.ts @@ -6,7 +6,7 @@ import { AdaptiveBotComponent } from 'botbuilder-dialogs-adaptive'; import { AdaptiveTeamsBotComponent } from '../src'; import { AdaptiveTestBotComponent, TestUtils } from 'botbuilder-dialogs-adaptive-testing'; import { ComponentDeclarativeTypes, ResourceExplorer } from 'botbuilder-dialogs-declarative'; -import { Configuration, ServiceCollection } from 'botbuilder-runtime-core'; +import { ServiceCollection, noOpConfiguration } from 'botbuilder-runtime-core'; describe('Conditional Tests', function () { let resourceExplorer: ResourceExplorer; @@ -15,16 +15,9 @@ describe('Conditional Tests', function () { declarativeTypes: [], }); - const configuration: Configuration = { - get(_path) { - return undefined; - }, - set(_path, _value) {}, - }; - - new AdaptiveBotComponent().configureServices(services, configuration); - new AdaptiveTeamsBotComponent().configureServices(services, configuration); - new AdaptiveTestBotComponent().configureServices(services, configuration); + new AdaptiveBotComponent().configureServices(services, noOpConfiguration); + new AdaptiveTeamsBotComponent().configureServices(services, noOpConfiguration); + new AdaptiveTestBotComponent().configureServices(services, noOpConfiguration); const declarativeTypes = services.mustMakeInstance('declarativeTypes'); diff --git a/libraries/botbuilder-dialogs-adaptive-testing/tests/utils.js b/libraries/botbuilder-dialogs-adaptive-testing/tests/utils.js index 38e09374a1..67f58e9688 100644 --- a/libraries/botbuilder-dialogs-adaptive-testing/tests/utils.js +++ b/libraries/botbuilder-dialogs-adaptive-testing/tests/utils.js @@ -5,18 +5,18 @@ const path = require('path'); const { AdaptiveBotComponent } = require('botbuilder-dialogs-adaptive'); const { AdaptiveTestBotComponent } = require('..'); const { ResourceExplorer } = require('botbuilder-dialogs-declarative'); -const { ServiceCollection } = require('botbuilder-runtime-core'); +const { ServiceCollection, noOpConfiguration } = require('botbuilder-runtime-core'); function makeResourceExplorer(resourceFolder, ...botComponents) { const services = new ServiceCollection({ declarativeTypes: [], }); - new AdaptiveBotComponent().configureServices(services, null); - new AdaptiveTestBotComponent().configureServices(services, null); + new AdaptiveBotComponent().configureServices(services, noOpConfiguration); + new AdaptiveTestBotComponent().configureServices(services, noOpConfiguration); botComponents.forEach((BotComponent) => { - new BotComponent().configureServices(services, null); + new BotComponent().configureServices(services, noOpConfiguration); }); const declarativeTypes = services.mustMakeInstance('declarativeTypes'); diff --git a/libraries/botbuilder-dialogs-declarative/tests/jsonLoad.test.js b/libraries/botbuilder-dialogs-declarative/tests/jsonLoad.test.js index 6e3dd6af14..e7453cea1e 100644 --- a/libraries/botbuilder-dialogs-declarative/tests/jsonLoad.test.js +++ b/libraries/botbuilder-dialogs-declarative/tests/jsonLoad.test.js @@ -3,7 +3,7 @@ const path = require('path'); const { ResourceExplorer } = require('../lib'); const { DialogManager } = require('botbuilder-dialogs'); const { QnACardBuilder, RankerTypes, QnAMakerClientKey, QnAMakerBotComponent } = require('botbuilder-ai'); -const { ServiceCollection } = require('botbuilder-runtime-core'); +const { ServiceCollection, noOpConfiguration } = require('botbuilder-runtime-core'); const { StringExpression } = require('adaptive-expressions'); const { @@ -142,8 +142,8 @@ describe('Json load tests', function () { declarativeTypes: [], }); - new AdaptiveBotComponent().configureServices(services, null); - new QnAMakerBotComponent().configureServices(services, null); + new AdaptiveBotComponent().configureServices(services, noOpConfiguration); + new QnAMakerBotComponent().configureServices(services, noOpConfiguration); const declarativeTypes = services.mustMakeInstance('declarativeTypes'); diff --git a/libraries/botbuilder-dialogs-declarative/tests/resourceExplorer.test.js b/libraries/botbuilder-dialogs-declarative/tests/resourceExplorer.test.js index 76db267212..5a23fa0068 100644 --- a/libraries/botbuilder-dialogs-declarative/tests/resourceExplorer.test.js +++ b/libraries/botbuilder-dialogs-declarative/tests/resourceExplorer.test.js @@ -2,7 +2,7 @@ const assert = require('assert'); const { AdaptiveBotComponent } = require('botbuilder-dialogs-adaptive'); const { DialogManager } = require('botbuilder-dialogs'); const { ResourceExplorer, FolderResourceProvider, ResourceChangeEvent } = require('../lib'); -const { ServiceCollection } = require('botbuilder-runtime-core'); +const { ServiceCollection, noOpConfiguration } = require('botbuilder-runtime-core'); const { TestAdapter, MemoryStorage, useBotState, UserState, ConversationState } = require('botbuilder-core'); const { extname, join } = require('path'); const { writeFileSync, existsSync, unlinkSync } = require('fs'); @@ -101,7 +101,7 @@ describe('ResourceExplorer', function () { declarativeTypes: [], }); - new AdaptiveBotComponent().configureServices(services, null); + new AdaptiveBotComponent().configureServices(services, noOpConfiguration); const declarativeTypes = services.mustMakeInstance('declarativeTypes'); const explorer = new ResourceExplorer({ declarativeTypes }).addFolders(join(__dirname, 'resources'), [], false); @@ -269,7 +269,7 @@ describe('ResourceExplorer', function () { declarativeTypes: [], }); - new AdaptiveBotComponent().configureServices(services, null); + new AdaptiveBotComponent().configureServices(services, noOpConfiguration); const declarativeTypes = services.mustMakeInstance('declarativeTypes'); const resourceExplorer = new ResourceExplorer({ declarativeTypes }).addFolder( diff --git a/libraries/botbuilder-dialogs/src/dialogsComponentRegistration.ts b/libraries/botbuilder-dialogs/src/dialogsComponentRegistration.ts index e4425234c9..79c58c110b 100644 --- a/libraries/botbuilder-dialogs/src/dialogsComponentRegistration.ts +++ b/libraries/botbuilder-dialogs/src/dialogsComponentRegistration.ts @@ -7,7 +7,7 @@ */ import { ComponentRegistration } from 'botbuilder-core'; -import { ServiceCollection } from 'botbuilder-runtime-core'; +import { ServiceCollection, noOpConfiguration } from 'botbuilder-runtime-core'; import { DialogsBotComponent } from './dialogsBotComponent'; import { ComponentMemoryScopes, ComponentPathResolvers, MemoryScope, PathResolver } from './memory'; @@ -25,7 +25,7 @@ export class DialogsComponentRegistration constructor() { super(); - new DialogsBotComponent().configureServices(this.services, null); + new DialogsBotComponent().configureServices(this.services, noOpConfiguration); } /** diff --git a/libraries/botbuilder-dialogs/src/memory/scopes/settingsMemoryScope.ts b/libraries/botbuilder-dialogs/src/memory/scopes/settingsMemoryScope.ts index 69d07d49a8..0842e8835c 100644 --- a/libraries/botbuilder-dialogs/src/memory/scopes/settingsMemoryScope.ts +++ b/libraries/botbuilder-dialogs/src/memory/scopes/settingsMemoryScope.ts @@ -6,7 +6,6 @@ * Licensed under the MIT License. */ -import { Configuration } from 'botbuilder-runtime-core'; import { DialogContext } from '../../dialogContext'; import { DialogTurnStateConstants } from '../../dialogTurnStateConstants'; import { MemoryScope } from './memoryScope'; diff --git a/libraries/botbuilder-runtime-core/src/configuration.ts b/libraries/botbuilder-runtime-core/src/configuration.ts index 1d5be3cf3b..4c1742fe40 100644 --- a/libraries/botbuilder-runtime-core/src/configuration.ts +++ b/libraries/botbuilder-runtime-core/src/configuration.ts @@ -21,3 +21,13 @@ export interface Configuration { */ set(path: string[], value: unknown): void; } + +// noOpConfiguration is useful for shimming new BotComponents back to ComponentRegistrations +export const noOpConfiguration: Configuration = { + get(_path: string[]): unknown | undefined { + return undefined; + }, + set(_path: string[], _value: unknown): void { + // no-op + }, +}; diff --git a/libraries/botbuilder-runtime/src/configuration.ts b/libraries/botbuilder-runtime/src/configuration.ts index b13dcacbcd..c15881ff5d 100644 --- a/libraries/botbuilder-runtime/src/configuration.ts +++ b/libraries/botbuilder-runtime/src/configuration.ts @@ -41,6 +41,11 @@ export class Configuration implements CoreConfiguration { * @returns the value, or undefined */ get(path: string[]): unknown | undefined { + // Note: empty path should yield the entire configuration + if (!path.length) { + return this.provider.get(); + } + return this.provider.get(this.key(path)); }