basant307/AI_Governance_Project
048
1"use strict";2/*3 * Copyright The OpenTelemetry Authors4 *5 * Licensed under the Apache License, Version 2.0 (the "License");6 * you may not use this file except in compliance with the License.7 * You may obtain a copy of the License at8 *9 * https://www.apache.org/licenses/LICENSE-2.010 *11 * Unless required by applicable law or agreed to in writing, software12 * distributed under the License is distributed on an "AS IS" BASIS,13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.14 * See the License for the specific language governing permissions and15 * limitations under the License.16 */17Object.defineProperty(exports, "__esModule", { value: true });18exports.ROOT_CONTEXT = exports.createContextKey = void 0;19/** Get a key to uniquely identify a context value */20function createContextKey(description) {21 // The specification states that for the same input, multiple calls should22 // return different keys. Due to the nature of the JS dependency management23 // system, this creates problems where multiple versions of some package24 // could hold different keys for the same property.25 //26 // Therefore, we use Symbol.for which returns the same key for the same input.27 return Symbol.for(description);28}29exports.createContextKey = createContextKey;30class BaseContext {31 /**32 * Construct a new context which inherits values from an optional parent context.33 *34 * @param parentContext a context from which to inherit values35 */36 constructor(parentContext) {37 // for minification38 const self = this;39 self._currentContext = parentContext ? new Map(parentContext) : new Map();40 self.getValue = (key) => self._currentContext.get(key);41 self.setValue = (key, value) => {42 const context = new BaseContext(self._currentContext);43 context._currentContext.set(key, value);44 return context;45 };46 self.deleteValue = (key) => {47 const context = new BaseContext(self._currentContext);48 context._currentContext.delete(key);49 return context;50 };51 }52}53/** The root context is used as the default parent context when there is no active context */54exports.ROOT_CONTEXT = new BaseContext();55//# sourceMappingURL=context.js.map