1 | "use strict";
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 | Object.defineProperty(exports, "__esModule", { value: true });
|
18 | exports.clear = exports.withTagContext = exports.setCurrentTagContext = exports.getCurrentTagContext = exports.EMPTY_TAG_MAP = void 0;
|
19 | const tag_map_1 = require("./tag-map");
|
20 | exports.EMPTY_TAG_MAP = new tag_map_1.TagMap();
|
21 | const CURRENT_TAG_MAP_KEY = 'current_tag_map';
|
22 |
|
23 | function getCurrentTagContext(contextManager) {
|
24 | const tagsFromContext = contextManager.get(CURRENT_TAG_MAP_KEY);
|
25 | if (tagsFromContext) {
|
26 | return makeDeepCopy(tagsFromContext);
|
27 | }
|
28 | return new tag_map_1.TagMap();
|
29 | }
|
30 | exports.getCurrentTagContext = getCurrentTagContext;
|
31 |
|
32 |
|
33 |
|
34 |
|
35 | function setCurrentTagContext(contextManager, tags) {
|
36 | contextManager.set(CURRENT_TAG_MAP_KEY, makeDeepCopy(tags));
|
37 | }
|
38 | exports.setCurrentTagContext = setCurrentTagContext;
|
39 |
|
40 |
|
41 |
|
42 |
|
43 |
|
44 |
|
45 |
|
46 | function withTagContext(contextManager, tags, fn) {
|
47 | const oldContext = getCurrentTagContext(contextManager);
|
48 | return contextManager.runAndReturn(() => {
|
49 | const newContext = new tag_map_1.TagMap();
|
50 | for (const [tagKey, tagValue] of oldContext.tags) {
|
51 | newContext.set(tagKey, tagValue);
|
52 | }
|
53 | for (const [tagKey, tagValue] of tags.tags) {
|
54 | newContext.set(tagKey, tagValue);
|
55 | }
|
56 | setCurrentTagContext(contextManager, newContext);
|
57 | return fn();
|
58 | });
|
59 | }
|
60 | exports.withTagContext = withTagContext;
|
61 |
|
62 | function clear(contextManager) {
|
63 | contextManager.set(CURRENT_TAG_MAP_KEY, new tag_map_1.TagMap());
|
64 | }
|
65 | exports.clear = clear;
|
66 | function makeDeepCopy(tags) {
|
67 | const tagsCopy = new tag_map_1.TagMap();
|
68 | for (const [tagKey, valueWithMetadata] of tags.tagsWithMetadata) {
|
69 | tagsCopy.set(tagKey, valueWithMetadata.tagValue, valueWithMetadata.tagMetadata);
|
70 | }
|
71 | return tagsCopy;
|
72 | }
|
73 |
|
\ | No newline at end of file |