@dynatrace-sdk/client-classic-environment-v2 3.7.1 → 3.7.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md
CHANGED
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @dynatrace-sdk/client-classic-environment-v2
|
|
2
2
|
|
|
3
|
-
[](https://www.npmjs.com/package/@dynatrace-sdk/client-classic-environment-v2/v/3.7.2)
|
|
4
4
|
[](https://opensource.org/licenses/Apache-2.0)
|
|
5
5
|
|
|
6
6
|
|
package/cjs/index.js
CHANGED
|
@@ -389,65 +389,92 @@ function mergeKeys(key1, key2) {
|
|
|
389
389
|
return key1;
|
|
390
390
|
return `${key1}.${key2}`;
|
|
391
391
|
}
|
|
392
|
-
function matchKey(key,
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
392
|
+
function matchKey(key, rules, cache) {
|
|
393
|
+
if (cache.has(key)) {
|
|
394
|
+
return cache.get(key);
|
|
395
|
+
}
|
|
396
|
+
for (const rule of rules) {
|
|
397
|
+
const pattern = Array.isArray(rule) ? rule[0] : rule;
|
|
398
|
+
const config = Array.isArray(rule) ? rule[1] : defaultRuleConfig;
|
|
399
|
+
if (key === pattern) {
|
|
400
|
+
const result = [pattern, config];
|
|
401
|
+
cache.set(key, result);
|
|
402
|
+
return result;
|
|
403
|
+
}
|
|
404
|
+
let i = 0;
|
|
405
|
+
let j = 0;
|
|
406
|
+
const keyLen = key.length;
|
|
407
|
+
const patternLen = pattern.length;
|
|
408
|
+
let isMatch = true;
|
|
409
|
+
while (i < keyLen && j < patternLen) {
|
|
410
|
+
let keyPartEnd = key.indexOf(".", i);
|
|
411
|
+
let patternPartEnd = pattern.indexOf(".", j);
|
|
412
|
+
if (keyPartEnd === -1)
|
|
413
|
+
keyPartEnd = keyLen;
|
|
414
|
+
if (patternPartEnd === -1)
|
|
415
|
+
patternPartEnd = patternLen;
|
|
416
|
+
const keyPart = key.slice(i, keyPartEnd);
|
|
417
|
+
const patternPart = pattern.slice(j, patternPartEnd);
|
|
418
|
+
if (patternPart !== "*" && patternPart !== "**" && keyPart !== patternPart) {
|
|
419
|
+
isMatch = false;
|
|
420
|
+
break;
|
|
421
|
+
}
|
|
422
|
+
i = keyPartEnd + 1;
|
|
423
|
+
j = patternPartEnd + 1;
|
|
400
424
|
}
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
if (keyPart !== ruleKeyParts[idx] && !wildcard) {
|
|
407
|
-
if (ruleKeyParts[idx] === "**") {
|
|
408
|
-
wildcard = true;
|
|
409
|
-
} else if (ruleKeyParts[idx] === "*") {
|
|
410
|
-
wildcard = true;
|
|
411
|
-
} else {
|
|
412
|
-
matchResult = false;
|
|
425
|
+
if (isMatch) {
|
|
426
|
+
if (j < patternLen) {
|
|
427
|
+
const remaining = pattern.slice(j);
|
|
428
|
+
if (remaining !== "**" && remaining !== "*") {
|
|
429
|
+
isMatch = false;
|
|
413
430
|
}
|
|
414
431
|
}
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
keyPartsReversed.forEach((keyPart, idx) => {
|
|
418
|
-
if (keyPart !== ruleKeyPartsReversed[idx] && !wildcard) {
|
|
419
|
-
if (ruleKeyPartsReversed[idx] === "**") {
|
|
420
|
-
wildcard = true;
|
|
421
|
-
} else if (ruleKeyPartsReversed[idx] === "*") {
|
|
422
|
-
wildcard = true;
|
|
423
|
-
} else {
|
|
424
|
-
matchResult = false;
|
|
425
|
-
}
|
|
432
|
+
if (i < keyLen && pattern.slice(j - 1) !== "**") {
|
|
433
|
+
isMatch = false;
|
|
426
434
|
}
|
|
427
|
-
}
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
435
|
+
}
|
|
436
|
+
if (isMatch) {
|
|
437
|
+
const result = [pattern, config];
|
|
438
|
+
cache.set(key, result);
|
|
439
|
+
return result;
|
|
440
|
+
}
|
|
432
441
|
}
|
|
442
|
+
cache.set(key, null);
|
|
433
443
|
return null;
|
|
434
444
|
}
|
|
435
445
|
var potentialMatchForRoot = (pattern, key) => pattern.startsWith(key) || pattern.startsWith("*") || pattern.startsWith("**");
|
|
436
446
|
var potentialMatch = (pattern, key) => pattern.startsWith(key) || pattern.includes("*") || pattern.includes("**");
|
|
437
447
|
function partialMatch(key, keyPatterns) {
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
let
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
448
|
+
const keyPatternsLen = keyPatterns.length;
|
|
449
|
+
if (!key.includes(".")) {
|
|
450
|
+
for (let i = 0; i < keyPatternsLen; i++) {
|
|
451
|
+
const pattern = keyPatterns[i];
|
|
452
|
+
if (potentialMatchForRoot(pattern, key))
|
|
453
|
+
return true;
|
|
454
|
+
}
|
|
455
|
+
return false;
|
|
456
|
+
}
|
|
457
|
+
let dotIndex = -1;
|
|
458
|
+
let currentKeyEnd = 0;
|
|
459
|
+
while ((dotIndex = key.indexOf(".", currentKeyEnd)) !== -1) {
|
|
460
|
+
const currentKey = key.slice(0, dotIndex);
|
|
461
|
+
const isRoot = !currentKey.includes(".");
|
|
462
|
+
for (let i = 0; i < keyPatternsLen; i++) {
|
|
463
|
+
const pattern = keyPatterns[i];
|
|
444
464
|
if (isRoot) {
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
465
|
+
if (potentialMatchForRoot(pattern, currentKey))
|
|
466
|
+
return true;
|
|
467
|
+
} else if (potentialMatch(pattern, currentKey))
|
|
468
|
+
return true;
|
|
469
|
+
}
|
|
470
|
+
currentKeyEnd = dotIndex + 1;
|
|
449
471
|
}
|
|
450
|
-
|
|
472
|
+
for (let i = 0; i < keyPatternsLen; i++) {
|
|
473
|
+
const pattern = keyPatterns[i];
|
|
474
|
+
if (potentialMatch(pattern, key))
|
|
475
|
+
return true;
|
|
476
|
+
}
|
|
477
|
+
return false;
|
|
451
478
|
}
|
|
452
479
|
var dateTimePattern = /^((?:(\d{4}-\d{2}-\d{2})T(\d{2}:\d{2}:\d{2}(?:\.\d+)?))(Z|[+-]\d{2}:\d{2})?)$/i;
|
|
453
480
|
function isDateLike(value) {
|
|
@@ -467,49 +494,48 @@ function transformValue(value, rules, direction) {
|
|
|
467
494
|
}
|
|
468
495
|
return value;
|
|
469
496
|
}
|
|
470
|
-
function walk(obj, direction,
|
|
471
|
-
if (
|
|
497
|
+
function walk(obj, direction, rules, rulesCache, keyPatterns, currentKey = "") {
|
|
498
|
+
if (rules.length <= 0) {
|
|
472
499
|
return obj;
|
|
473
500
|
}
|
|
474
|
-
if (!partialMatch(currentKey,
|
|
501
|
+
if (!partialMatch(currentKey, keyPatterns)) {
|
|
475
502
|
return obj;
|
|
476
503
|
}
|
|
477
504
|
if (Array.isArray(obj)) {
|
|
505
|
+
const match = matchKey(currentKey, rules, rulesCache);
|
|
478
506
|
obj.forEach((item, idx) => {
|
|
479
507
|
if (typeof item === "object" && item !== null) {
|
|
480
|
-
walk(item, direction,
|
|
481
|
-
} else {
|
|
482
|
-
|
|
483
|
-
if (match) {
|
|
484
|
-
obj[idx] = transformValue(obj[idx], match[1], direction);
|
|
485
|
-
}
|
|
508
|
+
walk(item, direction, rules, rulesCache, keyPatterns, currentKey);
|
|
509
|
+
} else if (match) {
|
|
510
|
+
obj[idx] = transformValue(obj[idx], match[1], direction);
|
|
486
511
|
}
|
|
487
512
|
});
|
|
488
513
|
}
|
|
489
514
|
if (typeof obj === "object" && obj !== null && !Array.isArray(obj)) {
|
|
490
515
|
for (const key of Object.keys(obj)) {
|
|
491
516
|
const mergedKey = mergeKeys(currentKey, key);
|
|
492
|
-
const match = matchKey(mergedKey,
|
|
517
|
+
const match = matchKey(mergedKey, rules, rulesCache);
|
|
493
518
|
if (match) {
|
|
494
519
|
obj[key] = transformValue(obj[key], match[1], direction);
|
|
495
520
|
}
|
|
496
|
-
walk(obj[key], direction,
|
|
521
|
+
walk(obj[key], direction, rules, rulesCache, keyPatterns, mergedKey);
|
|
497
522
|
}
|
|
498
523
|
}
|
|
499
524
|
return obj;
|
|
500
525
|
}
|
|
501
|
-
function
|
|
502
|
-
return
|
|
526
|
+
function flattenKeyPatterns(keyPatterns) {
|
|
527
|
+
return keyPatterns.map((k) => Array.isArray(k) ? k[0] : k);
|
|
503
528
|
}
|
|
504
|
-
function transform(direction, object,
|
|
505
|
-
const
|
|
506
|
-
|
|
529
|
+
function transform(direction, object, rules) {
|
|
530
|
+
const flatKeyPatterns = flattenKeyPatterns(rules);
|
|
531
|
+
const rulesCache = /* @__PURE__ */ new Map();
|
|
532
|
+
return walk(object, direction, rules, rulesCache, flatKeyPatterns);
|
|
507
533
|
}
|
|
508
|
-
function transformRequest(object,
|
|
509
|
-
return transform("from", object,
|
|
534
|
+
function transformRequest(object, rules) {
|
|
535
|
+
return transform("from", object, rules);
|
|
510
536
|
}
|
|
511
|
-
function transformResponse(object,
|
|
512
|
-
return transform("to", object,
|
|
537
|
+
function transformResponse(object, rules) {
|
|
538
|
+
return transform("to", object, rules);
|
|
513
539
|
}
|
|
514
540
|
|
|
515
541
|
// packages/client/classic-environment-v2/src/lib/utils/url-helpers.ts
|
package/dynatrace-metadata.json
CHANGED
package/esm/index.js
CHANGED
|
@@ -88,65 +88,92 @@ function mergeKeys(key1, key2) {
|
|
|
88
88
|
return key1;
|
|
89
89
|
return `${key1}.${key2}`;
|
|
90
90
|
}
|
|
91
|
-
function matchKey(key,
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
91
|
+
function matchKey(key, rules, cache) {
|
|
92
|
+
if (cache.has(key)) {
|
|
93
|
+
return cache.get(key);
|
|
94
|
+
}
|
|
95
|
+
for (const rule of rules) {
|
|
96
|
+
const pattern = Array.isArray(rule) ? rule[0] : rule;
|
|
97
|
+
const config = Array.isArray(rule) ? rule[1] : defaultRuleConfig;
|
|
98
|
+
if (key === pattern) {
|
|
99
|
+
const result = [pattern, config];
|
|
100
|
+
cache.set(key, result);
|
|
101
|
+
return result;
|
|
102
|
+
}
|
|
103
|
+
let i = 0;
|
|
104
|
+
let j = 0;
|
|
105
|
+
const keyLen = key.length;
|
|
106
|
+
const patternLen = pattern.length;
|
|
107
|
+
let isMatch = true;
|
|
108
|
+
while (i < keyLen && j < patternLen) {
|
|
109
|
+
let keyPartEnd = key.indexOf(".", i);
|
|
110
|
+
let patternPartEnd = pattern.indexOf(".", j);
|
|
111
|
+
if (keyPartEnd === -1)
|
|
112
|
+
keyPartEnd = keyLen;
|
|
113
|
+
if (patternPartEnd === -1)
|
|
114
|
+
patternPartEnd = patternLen;
|
|
115
|
+
const keyPart = key.slice(i, keyPartEnd);
|
|
116
|
+
const patternPart = pattern.slice(j, patternPartEnd);
|
|
117
|
+
if (patternPart !== "*" && patternPart !== "**" && keyPart !== patternPart) {
|
|
118
|
+
isMatch = false;
|
|
119
|
+
break;
|
|
120
|
+
}
|
|
121
|
+
i = keyPartEnd + 1;
|
|
122
|
+
j = patternPartEnd + 1;
|
|
99
123
|
}
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
if (keyPart !== ruleKeyParts[idx] && !wildcard) {
|
|
106
|
-
if (ruleKeyParts[idx] === "**") {
|
|
107
|
-
wildcard = true;
|
|
108
|
-
} else if (ruleKeyParts[idx] === "*") {
|
|
109
|
-
wildcard = true;
|
|
110
|
-
} else {
|
|
111
|
-
matchResult = false;
|
|
124
|
+
if (isMatch) {
|
|
125
|
+
if (j < patternLen) {
|
|
126
|
+
const remaining = pattern.slice(j);
|
|
127
|
+
if (remaining !== "**" && remaining !== "*") {
|
|
128
|
+
isMatch = false;
|
|
112
129
|
}
|
|
113
130
|
}
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
keyPartsReversed.forEach((keyPart, idx) => {
|
|
117
|
-
if (keyPart !== ruleKeyPartsReversed[idx] && !wildcard) {
|
|
118
|
-
if (ruleKeyPartsReversed[idx] === "**") {
|
|
119
|
-
wildcard = true;
|
|
120
|
-
} else if (ruleKeyPartsReversed[idx] === "*") {
|
|
121
|
-
wildcard = true;
|
|
122
|
-
} else {
|
|
123
|
-
matchResult = false;
|
|
124
|
-
}
|
|
131
|
+
if (i < keyLen && pattern.slice(j - 1) !== "**") {
|
|
132
|
+
isMatch = false;
|
|
125
133
|
}
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
134
|
+
}
|
|
135
|
+
if (isMatch) {
|
|
136
|
+
const result = [pattern, config];
|
|
137
|
+
cache.set(key, result);
|
|
138
|
+
return result;
|
|
139
|
+
}
|
|
131
140
|
}
|
|
141
|
+
cache.set(key, null);
|
|
132
142
|
return null;
|
|
133
143
|
}
|
|
134
144
|
var potentialMatchForRoot = (pattern, key) => pattern.startsWith(key) || pattern.startsWith("*") || pattern.startsWith("**");
|
|
135
145
|
var potentialMatch = (pattern, key) => pattern.startsWith(key) || pattern.includes("*") || pattern.includes("**");
|
|
136
146
|
function partialMatch(key, keyPatterns) {
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
let
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
147
|
+
const keyPatternsLen = keyPatterns.length;
|
|
148
|
+
if (!key.includes(".")) {
|
|
149
|
+
for (let i = 0; i < keyPatternsLen; i++) {
|
|
150
|
+
const pattern = keyPatterns[i];
|
|
151
|
+
if (potentialMatchForRoot(pattern, key))
|
|
152
|
+
return true;
|
|
153
|
+
}
|
|
154
|
+
return false;
|
|
155
|
+
}
|
|
156
|
+
let dotIndex = -1;
|
|
157
|
+
let currentKeyEnd = 0;
|
|
158
|
+
while ((dotIndex = key.indexOf(".", currentKeyEnd)) !== -1) {
|
|
159
|
+
const currentKey = key.slice(0, dotIndex);
|
|
160
|
+
const isRoot = !currentKey.includes(".");
|
|
161
|
+
for (let i = 0; i < keyPatternsLen; i++) {
|
|
162
|
+
const pattern = keyPatterns[i];
|
|
143
163
|
if (isRoot) {
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
164
|
+
if (potentialMatchForRoot(pattern, currentKey))
|
|
165
|
+
return true;
|
|
166
|
+
} else if (potentialMatch(pattern, currentKey))
|
|
167
|
+
return true;
|
|
168
|
+
}
|
|
169
|
+
currentKeyEnd = dotIndex + 1;
|
|
148
170
|
}
|
|
149
|
-
|
|
171
|
+
for (let i = 0; i < keyPatternsLen; i++) {
|
|
172
|
+
const pattern = keyPatterns[i];
|
|
173
|
+
if (potentialMatch(pattern, key))
|
|
174
|
+
return true;
|
|
175
|
+
}
|
|
176
|
+
return false;
|
|
150
177
|
}
|
|
151
178
|
var dateTimePattern = /^((?:(\d{4}-\d{2}-\d{2})T(\d{2}:\d{2}:\d{2}(?:\.\d+)?))(Z|[+-]\d{2}:\d{2})?)$/i;
|
|
152
179
|
function isDateLike(value) {
|
|
@@ -166,49 +193,48 @@ function transformValue(value, rules, direction) {
|
|
|
166
193
|
}
|
|
167
194
|
return value;
|
|
168
195
|
}
|
|
169
|
-
function walk(obj, direction,
|
|
170
|
-
if (
|
|
196
|
+
function walk(obj, direction, rules, rulesCache, keyPatterns, currentKey = "") {
|
|
197
|
+
if (rules.length <= 0) {
|
|
171
198
|
return obj;
|
|
172
199
|
}
|
|
173
|
-
if (!partialMatch(currentKey,
|
|
200
|
+
if (!partialMatch(currentKey, keyPatterns)) {
|
|
174
201
|
return obj;
|
|
175
202
|
}
|
|
176
203
|
if (Array.isArray(obj)) {
|
|
204
|
+
const match = matchKey(currentKey, rules, rulesCache);
|
|
177
205
|
obj.forEach((item, idx) => {
|
|
178
206
|
if (typeof item === "object" && item !== null) {
|
|
179
|
-
walk(item, direction,
|
|
180
|
-
} else {
|
|
181
|
-
|
|
182
|
-
if (match) {
|
|
183
|
-
obj[idx] = transformValue(obj[idx], match[1], direction);
|
|
184
|
-
}
|
|
207
|
+
walk(item, direction, rules, rulesCache, keyPatterns, currentKey);
|
|
208
|
+
} else if (match) {
|
|
209
|
+
obj[idx] = transformValue(obj[idx], match[1], direction);
|
|
185
210
|
}
|
|
186
211
|
});
|
|
187
212
|
}
|
|
188
213
|
if (typeof obj === "object" && obj !== null && !Array.isArray(obj)) {
|
|
189
214
|
for (const key of Object.keys(obj)) {
|
|
190
215
|
const mergedKey = mergeKeys(currentKey, key);
|
|
191
|
-
const match = matchKey(mergedKey,
|
|
216
|
+
const match = matchKey(mergedKey, rules, rulesCache);
|
|
192
217
|
if (match) {
|
|
193
218
|
obj[key] = transformValue(obj[key], match[1], direction);
|
|
194
219
|
}
|
|
195
|
-
walk(obj[key], direction,
|
|
220
|
+
walk(obj[key], direction, rules, rulesCache, keyPatterns, mergedKey);
|
|
196
221
|
}
|
|
197
222
|
}
|
|
198
223
|
return obj;
|
|
199
224
|
}
|
|
200
|
-
function
|
|
201
|
-
return
|
|
225
|
+
function flattenKeyPatterns(keyPatterns) {
|
|
226
|
+
return keyPatterns.map((k) => Array.isArray(k) ? k[0] : k);
|
|
202
227
|
}
|
|
203
|
-
function transform(direction, object,
|
|
204
|
-
const
|
|
205
|
-
|
|
228
|
+
function transform(direction, object, rules) {
|
|
229
|
+
const flatKeyPatterns = flattenKeyPatterns(rules);
|
|
230
|
+
const rulesCache = /* @__PURE__ */ new Map();
|
|
231
|
+
return walk(object, direction, rules, rulesCache, flatKeyPatterns);
|
|
206
232
|
}
|
|
207
|
-
function transformRequest(object,
|
|
208
|
-
return transform("from", object,
|
|
233
|
+
function transformRequest(object, rules) {
|
|
234
|
+
return transform("from", object, rules);
|
|
209
235
|
}
|
|
210
|
-
function transformResponse(object,
|
|
211
|
-
return transform("to", object,
|
|
236
|
+
function transformResponse(object, rules) {
|
|
237
|
+
return transform("to", object, rules);
|
|
212
238
|
}
|
|
213
239
|
|
|
214
240
|
// packages/client/classic-environment-v2/src/lib/utils/url-helpers.ts
|
package/package.json
CHANGED
|
@@ -2,6 +2,7 @@ type TransformRuleConfig = {
|
|
|
2
2
|
force?: boolean;
|
|
3
3
|
datetime?: boolean;
|
|
4
4
|
};
|
|
5
|
-
|
|
6
|
-
export declare function
|
|
5
|
+
type TransformRulesParam = Array<string | [string, TransformRuleConfig]>;
|
|
6
|
+
export declare function transformRequest<T = any>(object: T, rules: TransformRulesParam): T;
|
|
7
|
+
export declare function transformResponse<T = any>(object: T, rules: TransformRulesParam): T;
|
|
7
8
|
export {};
|