@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
@@ -2,6 +2,12 @@
2
2
 
3
3
  @dynatrace-sdk/client-classic-environment-v2
4
4
 
5
+ ## 3.7.2
6
+
7
+ ### Patch Changes
8
+
9
+ - Improve performance of date transformations. (APPDEV-12840)
10
+
5
11
  ## 3.7.1
6
12
 
7
13
  ### Patch Changes
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # @dynatrace-sdk/client-classic-environment-v2
2
2
 
3
- [![npm](https://img.shields.io/badge/npm-v3.7.1-blue)](https://www.npmjs.com/package/@dynatrace-sdk/client-classic-environment-v2/v/3.7.1)
3
+ [![npm](https://img.shields.io/badge/npm-v3.7.2-blue)](https://www.npmjs.com/package/@dynatrace-sdk/client-classic-environment-v2/v/3.7.2)
4
4
  [![License](https://img.shields.io/badge/License-Apache_2.0-blue.svg)](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, keys) {
393
- const match = keys.find((k) => {
394
- const ruleKey = Array.isArray(k) ? k[0] : k;
395
- if (key === ruleKey) {
396
- return true;
397
- }
398
- if (!key || !ruleKey) {
399
- return false;
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
- const [keyParts, ruleKeyParts] = [key.split("."), ruleKey.split(".")];
402
- const [keyPartsReversed, ruleKeyPartsReversed] = [[...keyParts].reverse(), [...ruleKeyParts].reverse()];
403
- let wildcard = false;
404
- let matchResult = true;
405
- keyParts.forEach((keyPart, idx) => {
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
- wildcard = false;
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
- return matchResult;
429
- });
430
- if (match) {
431
- return Array.isArray(match) ? match : [match, defaultRuleConfig];
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
- if (key.includes(".")) {
439
- const keyParts = key.split(".");
440
- let currentKey = "";
441
- return !!keyParts.find((keyPart) => {
442
- currentKey = mergeKeys(currentKey, keyPart);
443
- const isRoot = !currentKey.includes(".");
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
- return !!keyPatterns.find((k) => potentialMatchForRoot(k, currentKey));
446
- }
447
- return !!keyPatterns.find((k) => potentialMatch(k, currentKey));
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
- return !!keyPatterns.find((k) => potentialMatchForRoot(k, key));
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, keyPatterns, flatKeyPatterns, currentKey = "") {
471
- if (keyPatterns.length <= 0) {
497
+ function walk(obj, direction, rules, rulesCache, keyPatterns, currentKey = "") {
498
+ if (rules.length <= 0) {
472
499
  return obj;
473
500
  }
474
- if (!partialMatch(currentKey, flatKeyPatterns)) {
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, keyPatterns, flatKeyPatterns, currentKey);
481
- } else {
482
- const match = matchKey(currentKey, keyPatterns);
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, keyPatterns);
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, keyPatterns, flatKeyPatterns, mergedKey);
521
+ walk(obj[key], direction, rules, rulesCache, keyPatterns, mergedKey);
497
522
  }
498
523
  }
499
524
  return obj;
500
525
  }
501
- function flattenKeys(keys) {
502
- return keys.map((k) => Array.isArray(k) ? k[0] : k);
526
+ function flattenKeyPatterns(keyPatterns) {
527
+ return keyPatterns.map((k) => Array.isArray(k) ? k[0] : k);
503
528
  }
504
- function transform(direction, object, keys) {
505
- const flatKeys = flattenKeys(keys);
506
- return walk(object, direction, keys, flatKeys);
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, keys) {
509
- return transform("from", object, keys);
534
+ function transformRequest(object, rules) {
535
+ return transform("from", object, rules);
510
536
  }
511
- function transformResponse(object, keys) {
512
- return transform("to", object, keys);
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
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "dynagen": {
3
- "version": "0.18.1",
3
+ "version": "0.19.2",
4
4
  "template": {
5
5
  "name": "@dynatrace-sdk/template-typescript-client",
6
- "version": "0.33.6"
6
+ "version": "0.33.7"
7
7
  },
8
8
  "featureFlags": {}
9
9
  },
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, keys) {
92
- const match = keys.find((k) => {
93
- const ruleKey = Array.isArray(k) ? k[0] : k;
94
- if (key === ruleKey) {
95
- return true;
96
- }
97
- if (!key || !ruleKey) {
98
- return false;
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
- const [keyParts, ruleKeyParts] = [key.split("."), ruleKey.split(".")];
101
- const [keyPartsReversed, ruleKeyPartsReversed] = [[...keyParts].reverse(), [...ruleKeyParts].reverse()];
102
- let wildcard = false;
103
- let matchResult = true;
104
- keyParts.forEach((keyPart, idx) => {
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
- wildcard = false;
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
- return matchResult;
128
- });
129
- if (match) {
130
- return Array.isArray(match) ? match : [match, defaultRuleConfig];
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
- if (key.includes(".")) {
138
- const keyParts = key.split(".");
139
- let currentKey = "";
140
- return !!keyParts.find((keyPart) => {
141
- currentKey = mergeKeys(currentKey, keyPart);
142
- const isRoot = !currentKey.includes(".");
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
- return !!keyPatterns.find((k) => potentialMatchForRoot(k, currentKey));
145
- }
146
- return !!keyPatterns.find((k) => potentialMatch(k, currentKey));
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
- return !!keyPatterns.find((k) => potentialMatchForRoot(k, key));
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, keyPatterns, flatKeyPatterns, currentKey = "") {
170
- if (keyPatterns.length <= 0) {
196
+ function walk(obj, direction, rules, rulesCache, keyPatterns, currentKey = "") {
197
+ if (rules.length <= 0) {
171
198
  return obj;
172
199
  }
173
- if (!partialMatch(currentKey, flatKeyPatterns)) {
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, keyPatterns, flatKeyPatterns, currentKey);
180
- } else {
181
- const match = matchKey(currentKey, keyPatterns);
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, keyPatterns);
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, keyPatterns, flatKeyPatterns, mergedKey);
220
+ walk(obj[key], direction, rules, rulesCache, keyPatterns, mergedKey);
196
221
  }
197
222
  }
198
223
  return obj;
199
224
  }
200
- function flattenKeys(keys) {
201
- return keys.map((k) => Array.isArray(k) ? k[0] : k);
225
+ function flattenKeyPatterns(keyPatterns) {
226
+ return keyPatterns.map((k) => Array.isArray(k) ? k[0] : k);
202
227
  }
203
- function transform(direction, object, keys) {
204
- const flatKeys = flattenKeys(keys);
205
- return walk(object, direction, keys, flatKeys);
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, keys) {
208
- return transform("from", object, keys);
233
+ function transformRequest(object, rules) {
234
+ return transform("from", object, rules);
209
235
  }
210
- function transformResponse(object, keys) {
211
- return transform("to", object, keys);
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dynatrace-sdk/client-classic-environment-v2",
3
- "version": "3.7.1",
3
+ "version": "3.7.2",
4
4
  "description": "Client for the Dynatrace Environment API v2",
5
5
  "license": "Apache-2.0",
6
6
  "dependencies": {
@@ -2,6 +2,7 @@ type TransformRuleConfig = {
2
2
  force?: boolean;
3
3
  datetime?: boolean;
4
4
  };
5
- export declare function transformRequest<T = any>(object: T, keys: Array<string | [string, TransformRuleConfig]>): T;
6
- export declare function transformResponse<T = any>(object: T, keys: Array<string | [string, TransformRuleConfig]>): T;
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 {};