"use strict";
/*
 * Copyright The OpenTelemetry Authors
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
Object.defineProperty(exports, "__esModule", { value: true });
exports.createContextKey = exports.ROOT_CONTEXT = exports.BaseContext = void 0;
var BaseContext = /** @class */ (function () {
    /**
     * Construct a new context which inherits values from an optional parent context.
     *
     * @param parentContext a context from which to inherit values
     */
    function BaseContext(parentContext) {
        this._currentContext = parentContext ? new Map(parentContext) : new Map();
    }
    /**
     * Get a value from the context.
     *
     * @param key key which identifies a context value
     */
    BaseContext.prototype.getValue = function (key) {
        return this._currentContext.get(key);
    };
    /**
     * Create a new context which inherits from this context and has
     * the given key set to the given value.
     *
     * @param key context key for which to set the value
     * @param value value to set for the given key
     */
    BaseContext.prototype.setValue = function (key, value) {
        var context = new BaseContext(this._currentContext);
        context._currentContext.set(key, value);
        return context;
    };
    /**
     * Return a new context which inherits from this context but does
     * not contain a value for the given key.
     *
     * @param key context key for which to clear a value
     */
    BaseContext.prototype.deleteValue = function (key) {
        var context = new BaseContext(this._currentContext);
        context._currentContext.delete(key);
        return context;
    };
    return BaseContext;
}());
exports.BaseContext = BaseContext;
/** The root context is used as the default parent context when there is no active context */
exports.ROOT_CONTEXT = new BaseContext();
/** Get a key to uniquely identify a context value */
function createContextKey(description) {
    return Symbol.for(description);
}
exports.createContextKey = createContextKey;
//# sourceMappingURL=context.js.map