aimpress-chatbot/node_modules/botbuilder-core/lib/turnContextStateCollection.js
“SamoilenkoVadym” 55445dbc86
Some checks failed
Build and deploy Node.js app to Azure Web App - ChatBot2222 / build (push) Has been cancelled
Build and deploy Node.js app to Azure Web App - ChatBot2222 / deploy (push) Has been cancelled
Deploy bot to Azure
2025-04-27 19:55:19 +01:00

72 lines
No EOL
2.6 KiB
JavaScript

"use strict";
/**
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License.
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.TurnContextStateCollection = void 0;
const TURN_STATE_SCOPE_CACHE = Symbol('turnStateScopeCache');
/**
* Values persisted for the lifetime of the turn as part of the [TurnContext](xref:botbuilder-core.TurnContext).
*
* @remarks Typical values stored here are objects which are needed for the lifetime of a turn, such
* as [Storage](xref:botbuilder-core.Storage), [BotState](xref:botbuilder-core.BotState), [ConversationState](xref:botbuilder-core.ConversationState), [LanguageGenerator](xref:botbuilder-dialogs-adaptive.LanguageGenerator), [ResourceExplorer](xref:botbuilder-dialogs-declarative.ResourceExplorer), etc.
*/
class TurnContextStateCollection extends Map {
/**
* Gets a value from the [TurnContextStateCollection](xref:botbuilder-core.TurnContextStateCollection).
*
* @param key The values key.
* @returns The object; or null if no service is registered by the key.
*/
get(key) {
return super.get(key);
}
/**
* Push a value by key to the turn's context.
*
* @remarks
* The keys current value (if any) will be saved and can be restored by calling [pop()](#pop).
* @param key The values key.
* @param value The new value.
*/
push(key, value) {
// Get current value and add to scope cache
const current = this.get(key);
const cache = this.get(TURN_STATE_SCOPE_CACHE) || new Map();
if (cache.has(key)) {
cache.get(key).push(current);
}
else {
cache.set(key, [current]);
}
// Set new (or current) value and save cache
if (value == undefined) {
value = current;
}
this.set(key, value);
this.set(TURN_STATE_SCOPE_CACHE, cache);
}
/**
* Restores a keys previous value, and returns the value that was removed.
*
* @param key The values key.
* @returns The removed value.
*/
pop(key) {
// Get current value
const current = this.get(key);
// Get previous value from scope cache
let previous;
const cache = this.get(TURN_STATE_SCOPE_CACHE) || new Map();
if (cache.has(key)) {
previous = cache.get(key).pop();
}
// Restore previous value and save cache
this.set(key, previous);
this.set(TURN_STATE_SCOPE_CACHE, cache);
return current;
}
}
exports.TurnContextStateCollection = TurnContextStateCollection;
//# sourceMappingURL=turnContextStateCollection.js.map