@itwin/core-bentley 3.4.0-dev.8 → 3.5.0-dev.11

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.
Files changed (90) hide show
  1. package/CHANGELOG.md +25 -1
  2. package/lib/cjs/ByteStream.d.ts.map +1 -1
  3. package/lib/cjs/ByteStream.js +14 -4
  4. package/lib/cjs/ByteStream.js.map +1 -1
  5. package/lib/cjs/Compare.d.ts.map +1 -1
  6. package/lib/cjs/Compare.js +18 -6
  7. package/lib/cjs/Compare.js.map +1 -1
  8. package/lib/cjs/Dictionary.d.ts.map +1 -1
  9. package/lib/cjs/Dictionary.js.map +1 -1
  10. package/lib/cjs/Id.d.ts.map +1 -1
  11. package/lib/cjs/Id.js +15 -5
  12. package/lib/cjs/Id.js.map +1 -1
  13. package/lib/cjs/JsonUtils.d.ts.map +1 -1
  14. package/lib/cjs/JsonUtils.js +34 -16
  15. package/lib/cjs/JsonUtils.js.map +1 -1
  16. package/lib/cjs/LRUMap.d.ts.map +1 -1
  17. package/lib/cjs/LRUMap.js.map +1 -1
  18. package/lib/cjs/OneAtATimeAction.d.ts.map +1 -1
  19. package/lib/cjs/OneAtATimeAction.js +4 -1
  20. package/lib/cjs/OneAtATimeAction.js.map +1 -1
  21. package/lib/cjs/SortedArray.d.ts.map +1 -1
  22. package/lib/cjs/SortedArray.js +3 -1
  23. package/lib/cjs/SortedArray.js.map +1 -1
  24. package/lib/cjs/StringUtils.d.ts.map +1 -1
  25. package/lib/cjs/StringUtils.js +3 -1
  26. package/lib/cjs/StringUtils.js.map +1 -1
  27. package/lib/cjs/Time.d.ts +1 -1
  28. package/lib/cjs/Time.d.ts.map +1 -1
  29. package/lib/cjs/Time.js +9 -3
  30. package/lib/cjs/Time.js.map +1 -1
  31. package/lib/cjs/Tracing.d.ts +2 -2
  32. package/lib/cjs/Tracing.d.ts.map +1 -1
  33. package/lib/cjs/Tracing.js +4 -1
  34. package/lib/cjs/Tracing.js.map +1 -1
  35. package/lib/cjs/TypedArrayBuilder.d.ts +98 -0
  36. package/lib/cjs/TypedArrayBuilder.d.ts.map +1 -0
  37. package/lib/cjs/TypedArrayBuilder.js +135 -0
  38. package/lib/cjs/TypedArrayBuilder.js.map +1 -0
  39. package/lib/cjs/UnexpectedErrors.d.ts.map +1 -1
  40. package/lib/cjs/UnexpectedErrors.js +5 -2
  41. package/lib/cjs/UnexpectedErrors.js.map +1 -1
  42. package/lib/cjs/core-bentley.d.ts +1 -0
  43. package/lib/cjs/core-bentley.d.ts.map +1 -1
  44. package/lib/cjs/core-bentley.js +1 -0
  45. package/lib/cjs/core-bentley.js.map +1 -1
  46. package/lib/esm/ByteStream.d.ts.map +1 -1
  47. package/lib/esm/ByteStream.js +14 -4
  48. package/lib/esm/ByteStream.js.map +1 -1
  49. package/lib/esm/Compare.d.ts.map +1 -1
  50. package/lib/esm/Compare.js +18 -6
  51. package/lib/esm/Compare.js.map +1 -1
  52. package/lib/esm/Dictionary.d.ts.map +1 -1
  53. package/lib/esm/Dictionary.js.map +1 -1
  54. package/lib/esm/Id.d.ts.map +1 -1
  55. package/lib/esm/Id.js +15 -5
  56. package/lib/esm/Id.js.map +1 -1
  57. package/lib/esm/JsonUtils.d.ts.map +1 -1
  58. package/lib/esm/JsonUtils.js +34 -16
  59. package/lib/esm/JsonUtils.js.map +1 -1
  60. package/lib/esm/LRUMap.d.ts.map +1 -1
  61. package/lib/esm/LRUMap.js.map +1 -1
  62. package/lib/esm/OneAtATimeAction.d.ts.map +1 -1
  63. package/lib/esm/OneAtATimeAction.js +4 -1
  64. package/lib/esm/OneAtATimeAction.js.map +1 -1
  65. package/lib/esm/SortedArray.d.ts.map +1 -1
  66. package/lib/esm/SortedArray.js +3 -1
  67. package/lib/esm/SortedArray.js.map +1 -1
  68. package/lib/esm/StringUtils.d.ts.map +1 -1
  69. package/lib/esm/StringUtils.js +3 -1
  70. package/lib/esm/StringUtils.js.map +1 -1
  71. package/lib/esm/Time.d.ts +1 -1
  72. package/lib/esm/Time.d.ts.map +1 -1
  73. package/lib/esm/Time.js +9 -3
  74. package/lib/esm/Time.js.map +1 -1
  75. package/lib/esm/Tracing.d.ts +2 -2
  76. package/lib/esm/Tracing.d.ts.map +1 -1
  77. package/lib/esm/Tracing.js +4 -1
  78. package/lib/esm/Tracing.js.map +1 -1
  79. package/lib/esm/TypedArrayBuilder.d.ts +98 -0
  80. package/lib/esm/TypedArrayBuilder.d.ts.map +1 -0
  81. package/lib/esm/TypedArrayBuilder.js +128 -0
  82. package/lib/esm/TypedArrayBuilder.js.map +1 -0
  83. package/lib/esm/UnexpectedErrors.d.ts.map +1 -1
  84. package/lib/esm/UnexpectedErrors.js +5 -2
  85. package/lib/esm/UnexpectedErrors.js.map +1 -1
  86. package/lib/esm/core-bentley.d.ts +1 -0
  87. package/lib/esm/core-bentley.d.ts.map +1 -1
  88. package/lib/esm/core-bentley.js +1 -0
  89. package/lib/esm/core-bentley.js.map +1 -1
  90. package/package.json +5 -5
@@ -18,40 +18,52 @@ var JsonUtils;
18
18
  * @param defaultVal default value if json cannot be converted to boolean
19
19
  * @returns the value of json as a boolean, or default value
20
20
  */
21
- function asBool(json, defaultVal = false) { return isNullOrUndefined(json) ? defaultVal : !!json; }
21
+ function asBool(json, defaultVal = false) {
22
+ return isNullOrUndefined(json) ? defaultVal : !!json;
23
+ }
22
24
  JsonUtils.asBool = asBool;
23
25
  /** Get a value as an integer.
24
26
  * @param json the input JSON object
25
27
  * @param defaultVal default value if json cannot be converted to integer
26
28
  * @returns the value of json as an integer, or default value
27
29
  */
28
- function asInt(json, defaultVal = 0) { return (typeof json === "number") ? Math.trunc(json) : defaultVal; }
30
+ function asInt(json, defaultVal = 0) {
31
+ return (typeof json === "number") ? Math.trunc(json) : defaultVal;
32
+ }
29
33
  JsonUtils.asInt = asInt;
30
34
  /** Get a value as a double.
31
35
  * @param json the input JSON object
32
36
  * @param defaultVal default value if json cannot be converted to double
33
37
  * @returns the value of json as a double, or default value
34
38
  */
35
- function asDouble(json, defaultVal = 0) { return (typeof json === "number") ? json : defaultVal; }
39
+ function asDouble(json, defaultVal = 0) {
40
+ return (typeof json === "number") ? json : defaultVal;
41
+ }
36
42
  JsonUtils.asDouble = asDouble;
37
43
  /** Get a value as a string.
38
44
  * @param json the input JSON object
39
45
  * @param defaultVal default value if json cannot be converted to string
40
46
  * @returns the value of json as a string, or default value
41
47
  */
42
- function asString(json, defaultVal = "") { return isNullOrUndefined(json) ? defaultVal : json.toString(); }
48
+ function asString(json, defaultVal = "") {
49
+ return isNullOrUndefined(json) ? defaultVal : json.toString();
50
+ }
43
51
  JsonUtils.asString = asString;
44
52
  /** Get a value as an array.
45
53
  * @param json the input JSON object
46
54
  * @returns the input JSON object if it is an array, otherwise undefined
47
55
  */
48
- function asArray(json) { return Array.isArray(json) ? json : undefined; }
56
+ function asArray(json) {
57
+ return Array.isArray(json) ? json : undefined;
58
+ }
49
59
  JsonUtils.asArray = asArray;
50
60
  /** Get a value as an object.
51
61
  * @param json the input JSON object
52
62
  * @returns the input JSON object if it is an object, otherwise undefined
53
63
  */
54
- function asObject(json) { return "object" === typeof json ? json : undefined; }
64
+ function asObject(json) {
65
+ return "object" === typeof json ? json : undefined;
66
+ }
55
67
  JsonUtils.asObject = asObject;
56
68
  /** Set or remove a number on a json object, given a key name, a value, and a default value. Sets `json[key] = val` if val is *not* equal to the default,
57
69
  * otherwise `delete json[key]`. This is used to omit values from JSON strings that are of known defaults.
@@ -60,10 +72,12 @@ var JsonUtils;
60
72
  * @param val the value to set
61
73
  * @param defaultVal the default value.
62
74
  */
63
- function setOrRemoveNumber(json, key, val, defaultVal) { if (val === defaultVal)
64
- delete json[key];
65
- else
66
- json[key] = val; }
75
+ function setOrRemoveNumber(json, key, val, defaultVal) {
76
+ if (val === defaultVal)
77
+ delete json[key];
78
+ else
79
+ json[key] = val;
80
+ }
67
81
  JsonUtils.setOrRemoveNumber = setOrRemoveNumber;
68
82
  /** Set or remove a boolean on a json object, given a key name, a value, and a default value. Sets `json[key] = val` if val is *not* equal to the default,
69
83
  * otherwise `delete json[key]`. This is used to omit values from JSON strings that are of known defaults.
@@ -72,10 +86,12 @@ var JsonUtils;
72
86
  * @param val the value to set
73
87
  * @param defaultVal the default value.
74
88
  */
75
- function setOrRemoveBoolean(json, key, val, defaultVal) { if (val === defaultVal)
76
- delete json[key];
77
- else
78
- json[key] = val; }
89
+ function setOrRemoveBoolean(json, key, val, defaultVal) {
90
+ if (val === defaultVal)
91
+ delete json[key];
92
+ else
93
+ json[key] = val;
94
+ }
79
95
  JsonUtils.setOrRemoveBoolean = setOrRemoveBoolean;
80
96
  /** Determine if a Javascript object is equivalent to `{}`.
81
97
  * @param json The JSON object to test.
@@ -93,7 +109,9 @@ var JsonUtils;
93
109
  return undefined === json || isEmptyObject(json);
94
110
  }
95
111
  JsonUtils.isEmptyObjectOrUndefined = isEmptyObjectOrUndefined;
96
- function isNullOrUndefined(json) { return null === json || undefined === json; }
112
+ function isNullOrUndefined(json) {
113
+ return null === json || undefined === json;
114
+ }
97
115
  /** Determine if the input is a non-empty Javascript object.
98
116
  * @param value The value to test.
99
117
  * @returns true if `value` is an Object with at least one key.
@@ -117,7 +135,7 @@ var JsonUtils;
117
135
  // if it's an array, convert each member.
118
136
  if (Array.isArray(val)) {
119
137
  const arr = new Array(val.length);
120
- val.forEach((el, i) => { arr[i] = toObject(el); });
138
+ val.forEach((el, i) => arr[i] = toObject(el));
121
139
  return arr;
122
140
  }
123
141
  // Convert each property
@@ -1 +1 @@
1
- {"version":3,"file":"JsonUtils.js","sourceRoot":"","sources":["../../src/JsonUtils.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH;;GAEG;AACH,IAAiB,SAAS,CAmHzB;AAnHD,WAAiB,SAAS;IACxB;;;;OAIG;IACH,SAAgB,MAAM,CAAC,IAAS,EAAE,UAAU,GAAG,KAAK,IAAa,OAAO,iBAAiB,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,UAAU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EnB,mDAAmD;QACnD,IAAI,OAAO,GAAG,CAAC,MAAM,KAAK,WAAW;YACnC,OAAO,QAAQ,CAAC,GAAG,CAAC,MAAM,EAAE,CAAC,CAAC;QAEhC,yCAAyC;QACzC,IAAI,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE;YACtB,MAAM,GAAG,GAAG,IAAI,KAAK,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;YAClC,GAAG,CAAC,OAAO,CAAC,CAAC,EAAE,EAAE,CAAC,EAAE,EAAE,GAAG,GAAG,CAAC,CAAC,CAAC,GAAG,QAAQ,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;YACnD,OAAO,GAAG,CAAC;SACZ;QAED,wBAAwB;QACxB,MAAM,GAAG,GAAQ,EAAE,CAAC;QACpB,MAAM,CAAC,mBAAmB,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE;YAC/C,MAAM,YAAY,GAAG,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC;YACzC,IAAI,YAAY,KAAK,SAAS;gBAC5B,GAAG,CAAC,IAAI,CAAC,GAAG,YAAY,CAAC;QAC7B,CAAC,CAAC,CAAC;QAEH,OAAO,GAAG,CAAC;IACb,CAAC;IA3Be,kBAAQ,WA2BvB,CAAA;AAEH,CAAC,EAnHgB,SAAS,GAAT,iBAAS,KAAT,iBAAS,QAmHzB","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n/** @packageDocumentation\r\n * @module Json\r\n */\r\n\r\n/** Utility functions for converting from JSON objects, with default values.\r\n * @public\r\n */\r\nexport namespace JsonUtils {\r\n /** Get a value as a boolean.\r\n * @param json the input JSON object\r\n * @param defaultVal default value if json cannot be converted to boolean\r\n * @returns the value of json as a boolean, or default value\r\n */\r\n export function asBool(json: any, defaultVal = false): boolean { return isNullOrUndefined(json) ? defaultVal : !!json; }\r\n /** Get a value as an integer.\r\n * @param json the input JSON object\r\n * @param defaultVal default value if json cannot be converted to integer\r\n * @returns the value of json as an integer, or default value\r\n */\r\n export function asInt(json: any, defaultVal = 0): number { return (typeof json === \"number\") ? Math.trunc(json) : defaultVal; }\r\n /** Get a value as a double.\r\n * @param json the input JSON object\r\n * @param defaultVal default value if json cannot be converted to double\r\n * @returns the value of json as a double, or default value\r\n */\r\n export function asDouble(json: any, defaultVal = 0): number { return (typeof json === \"number\") ? json : defaultVal; }\r\n /** Get a value as a string.\r\n * @param json the input JSON object\r\n * @param defaultVal default value if json cannot be converted to string\r\n * @returns the value of json as a string, or default value\r\n */\r\n export function asString(json: any, defaultVal = \"\"): string { return isNullOrUndefined(json) ? defaultVal : json.toString(); }\r\n\r\n /** Get a value as an array.\r\n * @param json the input JSON object\r\n * @returns the input JSON object if it is an array, otherwise undefined\r\n */\r\n export function asArray(json: any): any { return Array.isArray(json) ? json : undefined; }\r\n\r\n /** Get a value as an object.\r\n * @param json the input JSON object\r\n * @returns the input JSON object if it is an object, otherwise undefined\r\n */\r\n export function asObject(json: any): any { return \"object\" === typeof json ? json : undefined; }\r\n\r\n /** Set or remove a number on a json object, given a key name, a value, and a default value. Sets `json[key] = val` if val is *not* equal to the default,\r\n * otherwise `delete json[key]`. This is used to omit values from JSON strings that are of known defaults.\r\n * @param json the JSON object to affect\r\n * @param key the name of the member to set or remove\r\n * @param val the value to set\r\n * @param defaultVal the default value.\r\n */\r\n export function setOrRemoveNumber(json: any, key: string, val: number, defaultVal: number) { if (val === defaultVal) delete json[key]; else json[key] = val; }\r\n\r\n /** Set or remove a boolean on a json object, given a key name, a value, and a default value. Sets `json[key] = val` if val is *not* equal to the default,\r\n * otherwise `delete json[key]`. This is used to omit values from JSON strings that are of known defaults.\r\n * @param json the JSON object to affect\r\n * @param key the name of the member to set or remove\r\n * @param val the value to set\r\n * @param defaultVal the default value.\r\n */\r\n export function setOrRemoveBoolean(json: any, key: string, val: boolean, defaultVal: boolean) { if (val === defaultVal) delete json[key]; else json[key] = val; }\r\n\r\n /** Determine if a Javascript object is equivalent to `{}`.\r\n * @param json The JSON object to test.\r\n * @returns true if `json` is an Object with no keys.\r\n */\r\n export function isEmptyObject(json: any): boolean {\r\n return \"object\" === typeof json && 0 === Object.keys(json).length;\r\n }\r\n\r\n /** Determine if the input is undefined or an empty Javascript object.\r\n * @param json The JSON object to test.\r\n * @returns true if `json` is undefined or is an Object with no keys (equivalent to `{}`).\r\n */\r\n export function isEmptyObjectOrUndefined(json: any): boolean {\r\n return undefined === json || isEmptyObject(json);\r\n }\r\n\r\n function isNullOrUndefined(json: any): boolean { return null === json || undefined === json; }\r\n\r\n /** Determine if the input is a non-empty Javascript object.\r\n * @param value The value to test.\r\n * @returns true if `value` is an Object with at least one key.\r\n */\r\n export function isNonEmptyObject(value: any): value is Object {\r\n return !isEmptyObjectOrUndefined(value);\r\n }\r\n\r\n /**\r\n * Convert the input object into a \"pure\" JavaScript object, with only instances of \"object\" or primitives in the returned value.\r\n * Works recursively for object members, and over arrays entries. Calls \"toJSON\" on any members that implement it.\r\n */\r\n export function toObject(val: any): any {\r\n if (typeof val === \"boolean\" || typeof val === \"number\" || typeof val === \"string\")\r\n return val;\r\n\r\n if (typeof val !== \"object\")\r\n return undefined;\r\n\r\n // See if the object has toJSON() function defined.\r\n if (typeof val.toJSON !== \"undefined\")\r\n return toObject(val.toJSON());\r\n\r\n // if it's an array, convert each member.\r\n if (Array.isArray(val)) {\r\n const arr = new Array(val.length);\r\n val.forEach((el, i) => { arr[i] = toObject(el); });\r\n return arr;\r\n }\r\n\r\n // Convert each property\r\n const out: any = {};\r\n Object.getOwnPropertyNames(val).forEach((prop) => {\r\n const transformVal = toObject(val[prop]);\r\n if (transformVal !== undefined)\r\n out[prop] = transformVal;\r\n });\r\n\r\n return out;\r\n }\r\n\r\n}\r\n"]}
1
+ {"version":3,"file":"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0BAAgB,mBAE/B,CAAA;IAED;;;OAGG;IACH,SAAgB,QAAQ,CAAC,GAAQ;QAC/B,IAAI,OAAO,GAAG,KAAK,SAAS,IAAI,OAAO,GAAG,KAAK,QAAQ,IAAI,OAAO,GAAG,KAAK,QAAQ;YAChF,OAAO,GAAG,CAAC;QAEb,IAAI,OAAO,GAAG,KAAK,QAAQ;YACzB,OAAO,SAAS,CAAC;QAEnB,mDAAmD;QACnD,IAAI,OAAO,GAAG,CAAC,MAAM,KAAK,WAAW;YACnC,OAAO,QAAQ,CAAC,GAAG,CAAC,MAAM,EAAE,CAAC,CAAC;QAEhC,yCAAyC;QACzC,IAAI,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE;YACtB,MAAM,GAAG,GAAG,IAAI,KAAK,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;YAClC,GAAG,CAAC,OAAO,CAAC,CAAC,EAAE,EAAE,CAAC,EAAE,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,QAAQ,CAAC,EAAE,CAAC,CAAC,CAAC;YAC9C,OAAO,GAAG,CAAC;SACZ;QAED,wBAAwB;QACxB,MAAM,GAAG,GAAQ,EAAE,CAAC;QACpB,MAAM,CAAC,mBAAmB,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE;YAC/C,MAAM,YAAY,GAAG,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC;YACzC,IAAI,YAAY,KAAK,SAAS;gBAC5B,GAAG,CAAC,IAAI,CAAC,GAAG,YAAY,CAAC;QAC7B,CAAC,CAAC,CAAC;QAEH,OAAO,GAAG,CAAC;IACb,CAAC;IA3Be,kBAAQ,WA2BvB,CAAA;AAEH,CAAC,EA3IgB,SAAS,GAAT,iBAAS,KAAT,iBAAS,QA2IzB","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n/** @packageDocumentation\r\n * @module Json\r\n */\r\n\r\n/** Utility functions for converting from JSON objects, with default values.\r\n * @public\r\n */\r\nexport namespace JsonUtils {\r\n /** Get a value as a boolean.\r\n * @param json the input JSON object\r\n * @param defaultVal default value if json cannot be converted to boolean\r\n * @returns the value of json as a boolean, or default value\r\n */\r\n export function asBool(json: any, defaultVal = false): boolean {\r\n return isNullOrUndefined(json) ? defaultVal : !!json;\r\n }\r\n /** Get a value as an integer.\r\n * @param json the input JSON object\r\n * @param defaultVal default value if json cannot be converted to integer\r\n * @returns the value of json as an integer, or default value\r\n */\r\n export function asInt(json: any, defaultVal = 0): number {\r\n return (typeof json === \"number\") ? Math.trunc(json) : defaultVal;\r\n }\r\n /** Get a value as a double.\r\n * @param json the input JSON object\r\n * @param defaultVal default value if json cannot be converted to double\r\n * @returns the value of json as a double, or default value\r\n */\r\n export function asDouble(json: any, defaultVal = 0): number {\r\n return (typeof json === \"number\") ? json : defaultVal;\r\n }\r\n /** Get a value as a string.\r\n * @param json the input JSON object\r\n * @param defaultVal default value if json cannot be converted to string\r\n * @returns the value of json as a string, or default value\r\n */\r\n export function asString(json: any, defaultVal = \"\"): string {\r\n return isNullOrUndefined(json) ? defaultVal : json.toString();\r\n }\r\n\r\n /** Get a value as an array.\r\n * @param json the input JSON object\r\n * @returns the input JSON object if it is an array, otherwise undefined\r\n */\r\n export function asArray(json: any): any {\r\n return Array.isArray(json) ? json : undefined;\r\n }\r\n\r\n /** Get a value as an object.\r\n * @param json the input JSON object\r\n * @returns the input JSON object if it is an object, otherwise undefined\r\n */\r\n export function asObject(json: any): any {\r\n return \"object\" === typeof json ? json : undefined;\r\n }\r\n\r\n /** Set or remove a number on a json object, given a key name, a value, and a default value. Sets `json[key] = val` if val is *not* equal to the default,\r\n * otherwise `delete json[key]`. This is used to omit values from JSON strings that are of known defaults.\r\n * @param json the JSON object to affect\r\n * @param key the name of the member to set or remove\r\n * @param val the value to set\r\n * @param defaultVal the default value.\r\n */\r\n export function setOrRemoveNumber(json: any, key: string, val: number, defaultVal: number) {\r\n if (val === defaultVal)\r\n delete json[key];\r\n else\r\n json[key] = val;\r\n }\r\n\r\n /** Set or remove a boolean on a json object, given a key name, a value, and a default value. Sets `json[key] = val` if val is *not* equal to the default,\r\n * otherwise `delete json[key]`. This is used to omit values from JSON strings that are of known defaults.\r\n * @param json the JSON object to affect\r\n * @param key the name of the member to set or remove\r\n * @param val the value to set\r\n * @param defaultVal the default value.\r\n */\r\n export function setOrRemoveBoolean(json: any, key: string, val: boolean, defaultVal: boolean) {\r\n if (val === defaultVal)\r\n delete json[key];\r\n else\r\n json[key] = val;\r\n }\r\n\r\n /** Determine if a Javascript object is equivalent to `{}`.\r\n * @param json The JSON object to test.\r\n * @returns true if `json` is an Object with no keys.\r\n */\r\n export function isEmptyObject(json: any): boolean {\r\n return \"object\" === typeof json && 0 === Object.keys(json).length;\r\n }\r\n\r\n /** Determine if the input is undefined or an empty Javascript object.\r\n * @param json The JSON object to test.\r\n * @returns true if `json` is undefined or is an Object with no keys (equivalent to `{}`).\r\n */\r\n export function isEmptyObjectOrUndefined(json: any): boolean {\r\n return undefined === json || isEmptyObject(json);\r\n }\r\n\r\n function isNullOrUndefined(json: any): boolean {\r\n return null === json || undefined === json;\r\n }\r\n\r\n /** Determine if the input is a non-empty Javascript object.\r\n * @param value The value to test.\r\n * @returns true if `value` is an Object with at least one key.\r\n */\r\n export function isNonEmptyObject(value: any): value is Object {\r\n return !isEmptyObjectOrUndefined(value);\r\n }\r\n\r\n /**\r\n * Convert the input object into a \"pure\" JavaScript object, with only instances of \"object\" or primitives in the returned value.\r\n * Works recursively for object members, and over arrays entries. Calls \"toJSON\" on any members that implement it.\r\n */\r\n export function toObject(val: any): any {\r\n if (typeof val === \"boolean\" || typeof val === \"number\" || typeof val === \"string\")\r\n return val;\r\n\r\n if (typeof val !== \"object\")\r\n return undefined;\r\n\r\n // See if the object has toJSON() function defined.\r\n if (typeof val.toJSON !== \"undefined\")\r\n return toObject(val.toJSON());\r\n\r\n // if it's an array, convert each member.\r\n if (Array.isArray(val)) {\r\n const arr = new Array(val.length);\r\n val.forEach((el, i) => arr[i] = toObject(el));\r\n return arr;\r\n }\r\n\r\n // Convert each property\r\n const out: any = {};\r\n Object.getOwnPropertyNames(val).forEach((prop) => {\r\n const transformVal = toObject(val[prop]);\r\n if (transformVal !== undefined)\r\n out[prop] = transformVal;\r\n });\r\n\r\n return out;\r\n }\r\n\r\n}\r\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"LRUMap.d.ts","sourceRoot":"","sources":["../../src/LRUMap.ts"],"names":[],"mappings":"AAIA;;GAEG;AAEH,OAAO,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAC;AAG9C;;;;GAIG;AAEH;;GAEG;AACH,qBAAa,KAAK,CAAC,CAAC,EAAE,CAAC;IAGF,GAAG,EAAE,CAAC;IAAS,KAAK,EAAE,CAAC;IAFnC,KAAK,CAAC,EAAE,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IACpB,KAAK,CAAC,EAAE,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;gBACR,GAAG,EAAE,CAAC,EAAS,KAAK,EAAE,CAAC;CAC3C;AA6CD;;;GAGG;AACH,MAAM,WAAW,cAAc,CAAC,CAAC,EAAE,CAAC;IAClC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,KAAK,IAAI,IAAI,CAAC;IACd,GAAG,CAAC,GAAG,EAAE,CAAC,GAAG,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,SAAS,CAAC;IACrC,GAAG,CAAC,GAAG,EAAE,CAAC,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,IAAI,CAAC;IACtC,GAAG,CAAC,GAAG,EAAE,CAAC,GAAG,OAAO,CAAC;IACrB,MAAM,CAAC,GAAG,EAAE,CAAC,GAAG,IA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AAG,EAAE,CAAC;QACX,IAAI,KAAK,GAAG,IAAI,CAAC,MAAM,CAAC;QACxB,OAAO,KAAK,EAAE;YACZ,CAAC,IAAI,GAAG,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,KAAK,CAAC,KAAK,EAAE,CAAC;YAC3C,KAAK,GAAG,KAAK,CAAC,KAAK,CAAC;YACpB,IAAI,KAAK,EAAE;gBACT,CAAC,IAAI,KAAK,CAAC;aACZ;SACF;QACD,OAAO,CAAC,CAAC;IACX,CAAC;CACF;AAzPD,4BAyPC;AAED;;GAEG;AACH,MAAa,MAAa,SAAQ,QAAc;IAC9C;;OAEG;IACH,YAAY,KAAa;QACvB,KAAK,CAAC,KAAK,EAAE,IAAI,GAAG,EAAkB,CAAC,CAAC;IAC1C,CAAC;CACF;AAPD,wBAOC;AAED;;GAEG;AACH,MAAa,aAAoB,SAAQ,QAAc;IACrD;;;;OAIG;IACH,YAAY,KAAa,EAAE,WAAiC;QAC1D,KAAK,CAAC,KAAK,EAAE,IAAI,uBAAU,CAAiB,WAAW,CAAC,CAAC,CAAC;IAC5D,CAAC;CACF;AATD,sCASC","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n/** @packageDocumentation\r\n * @module Collections\r\n */\r\n\r\nimport { OrderedComparator } from \"./Compare\";\r\nimport { Dictionary } from \"./Dictionary\";\r\n\r\n/**\r\n * Derived from:\r\n * Licensed under MIT. Copyright (c) 2010 Rasmus Andersson <http://hunch.se/>\r\n * See README.md at https://github.com/rsms/js-lru for details.\r\n */\r\n\r\n/** An entry holds the key and value, and pointers to any older and newer entries.\r\n * @public\r\n */\r\nexport class Entry<K, V> {\r\n public newer?: Entry<K, V>;\r\n public older?: Entry<K, V>;\r\n constructor(public key: K, public value: V) { }\r\n}\r\n\r\nclass EntryIterator<K, V> implements Iterator<[K, V] | undefined> {\r\n private _entry: Entry<K, V> | undefined;\r\n constructor(oldestEntry: Entry<K, V>) {\r\n this._entry = oldestEntry;\r\n }\r\n public next() {\r\n const ent = this._entry;\r\n if (!ent)\r\n return { done: true, value: undefined };\r\n this._entry = ent.newer;\r\n const val: [K, V] = [ent.key, ent.value];\r\n return { done: false, value: val };\r\n }\r\n}\r\n\r\nclass KeyIterator<K, V> implements Iterator<K | undefined> {\r\n private _entry: Entry<K, V> | undefined;\r\n constructor(oldestEntry: Entry<K, V>) {\r\n this._entry = oldestEntry;\r\n }\r\n public next() {\r\n const ent = this._entry;\r\n if (!ent)\r\n return { done: true, value: undefined };\r\n this._entry = ent.newer;\r\n return { done: false, value: ent.key };\r\n }\r\n}\r\n\r\nclass ValueIterator<K, V> implements Iterator<V | undefined> {\r\n private _entry: Entry<K, V> | undefined;\r\n constructor(oldestEntry: Entry<K, V>) {\r\n this._entry = oldestEntry;\r\n }\r\n public next() {\r\n const ent = this._entry;\r\n if (!ent)\r\n return { done: true, value: undefined };\r\n this._entry = ent.newer;\r\n return { done: false, value: ent.value };\r\n }\r\n}\r\n\r\n/** The interface that must be satisfied by the underlying container type used by a LRUCache.\r\n * Compatible with a [[Dictionary]] or a standard Map.\r\n * @public\r\n */\r\nexport interface EntryContainer<K, V> {\r\n readonly size: number;\r\n clear(): void;\r\n get(key: K): Entry<K, V> | undefined;\r\n set(key: K, value: Entry<K, V>): void;\r\n has(key: K): boolean;\r\n delete(key: K): void;\r\n}\r\n\r\n/**\r\n * A mapping of a key/value pairs, where the size of the cache can be limited.\r\n *\r\n * When entries are inserted, if the cache is \"full\", the\r\n * least-recently-used (LRU) value is dropped. When entries are retrieved, they are moved to the front of the LRU list.\r\n *\r\n * Illustration of the design:\r\n *\r\n * ```\r\n *\r\n * entry entry entry entry\r\n * ______ ______ ______ ______\r\n * | head |.newer => | |.newer => | |.newer => | tail |\r\n * | A | | B | | C | | D |\r\n * |______| <= older.|______| <= older.|______| <= older.|______|\r\n *\r\n * removed <-- <-- <-- <-- <-- <-- <-- <-- <-- <-- <-- added\r\n * ```\r\n * @public\r\n */\r\nexport class LRUCache<K, V> {\r\n private _container: EntryContainer<K, V>;\r\n\r\n /** Current number of items */\r\n public size: number;\r\n\r\n /** Maximum number of items this cache can hold */\r\n public limit: number;\r\n\r\n /** Least recently-used entry. Invalidated when cache is modified. */\r\n public oldest?: Entry<K, V>;\r\n\r\n /** Most recently-used entry. Invalidated when cache is modified. */\r\n public newest?: Entry<K, V>;\r\n\r\n /**\r\n * Construct a new LRUCache to hold up to `limit` entries.\r\n */\r\n public constructor(limit: number, container: EntryContainer<K, V>) {\r\n this.size = 0;\r\n this.limit = limit;\r\n this.oldest = this.newest = undefined;\r\n this._container = container;\r\n }\r\n\r\n private markEntryAsUsed(entry: Entry<K, V>) {\r\n if (entry === this.newest)\r\n return; // Already the most recently used entry, so no need to update the list\r\n\r\n // HEAD--------------TAIL\r\n // <.older .newer>\r\n // <--- add direction --\r\n // A B C <D> E\r\n if (entry.newer) {\r\n if (entry === this.oldest) {\r\n this.oldest = entry.newer;\r\n }\r\n entry.newer.older = entry.older; // C <-- E.\r\n }\r\n if (entry.older) {\r\n entry.older.newer = entry.newer; // C. --> E\r\n }\r\n entry.newer = undefined; // D --x\r\n entry.older = this.newest; // D. --> E\r\n if (this.newest) {\r\n this.newest.newer = entry; // E. <-- D\r\n }\r\n this.newest = entry;\r\n }\r\n\r\n /** Replace all values in this cache with key-value pairs (2-element Arrays) from provided iterable. */\r\n public assign(entries: Iterable<[K, V]>): void {\r\n let entry;\r\n let limit = this.limit || Number.MAX_VALUE;\r\n this._container.clear();\r\n const it = entries[Symbol.iterator]();\r\n for (let itv = it.next(); !itv.done; itv = it.next()) {\r\n const e = new Entry(itv.value[0], itv.value[1]);\r\n this._container.set(e.key, e);\r\n if (!entry) {\r\n this.oldest = e;\r\n } else {\r\n entry.newer = e;\r\n e.older = entry;\r\n }\r\n entry = e;\r\n if (limit-- === 0) {\r\n throw new Error(\"overflow\");\r\n }\r\n }\r\n this.newest = entry;\r\n this.size = this._container.size;\r\n }\r\n\r\n /** Get and register recent use of <key>.\r\n * Returns the value associated with <key> or undefined if not in cache.\r\n */\r\n public get(key: K): V | undefined {\r\n // First, find our cache entry\r\n const entry = this._container.get(key);\r\n if (!entry)\r\n return; // Not cached. Sorry.\r\n // As <key> was found in the cache, register it as being requested recently\r\n this.markEntryAsUsed(entry);\r\n return entry.value;\r\n }\r\n\r\n /** Put <value> into the cache associated with <key>. Replaces any existing entry with the same key.\r\n * @returns `this`.\r\n */\r\n public set(key: K, value: V): LRUCache<K, V> {\r\n let entry = this._container.get(key);\r\n if (entry) {\r\n // update existing\r\n entry.value = value;\r\n this.markEntryAsUsed(entry);\r\n return this;\r\n }\r\n\r\n // new entry\r\n this._container.set(key, (entry = new Entry(key, value)));\r\n\r\n if (this.newest) {\r\n // link previous tail to the new tail (entry)\r\n this.newest.newer = entry;\r\n entry.older = this.newest;\r\n } else {\r\n // we're first in\r\n this.oldest = entry;\r\n }\r\n\r\n // add new entry to the end of the linked list -- it is now the freshest entry.\r\n this.newest = entry;\r\n ++this.size;\r\n if (this.size > this.limit) {\r\n // we hit the limit -- remove the head\r\n this.shift();\r\n }\r\n return this;\r\n }\r\n\r\n /** Purge the least recently used (oldest) entry from the cache.\r\n * @returns The removed entry or undefined if the cache was empty.\r\n */\r\n public shift(): [K, V] | undefined {\r\n const entry = this.oldest;\r\n if (entry) {\r\n if (entry.newer) {\r\n // advance the list\r\n this.oldest = entry.newer;\r\n this.oldest.older = undefined;\r\n } else {\r\n // the cache is exhausted\r\n this.oldest = undefined;\r\n this.newest = undefined;\r\n }\r\n // Remove last strong reference to <entry> and remove links from the purged\r\n // entry being returned:\r\n entry.newer = entry.older = undefined;\r\n this._container.delete(entry.key);\r\n --this.size;\r\n return [entry.key, entry.value];\r\n }\r\n return undefined;\r\n }\r\n\r\n /** Access value for `key` without registering recent use. Useful if you do not\r\n * want to change the state of the cache, but only \"peek\" at it.\r\n * @returns The value associated with `key` if found, or undefined if not found.\r\n */\r\n public find(key: K): V | undefined {\r\n const e = this._container.get(key);\r\n return e ? e.value : undefined;\r\n }\r\n\r\n /** Check if there's a value for key in the cache without registering recent use. */\r\n public has(key: K): boolean {\r\n return this._container.has(key);\r\n }\r\n\r\n /** Remove entry `key` from cache and return its value.\r\n * @returns The removed value, or undefined if not found.\r\n */\r\n public delete(key: K): V | undefined {\r\n const entry = this._container.get(key);\r\n if (!entry) return;\r\n this._container.delete(entry.key);\r\n if (entry.newer && entry.older) {\r\n // re-link the older entry with the newer entry\r\n entry.older.newer = entry.newer;\r\n entry.newer.older = entry.older;\r\n } else if (entry.newer) {\r\n // remove the link to us\r\n entry.newer.older = undefined;\r\n // link the newer entry to head\r\n this.oldest = entry.newer;\r\n } else if (entry.older) {\r\n // remove the link to us\r\n entry.older.newer = undefined;\r\n // link the newer entry to head\r\n this.newest = entry.older;\r\n } else { // if(entry.older === undefined && entry.newer === undefined) {\r\n this.oldest = this.newest = undefined;\r\n }\r\n\r\n this.size--;\r\n return entry.value;\r\n }\r\n\r\n /** Removes all entries */\r\n public clear(): void {\r\n // Note: clearing links should be safe, as we don't expose live links to user\r\n this.oldest = this.newest = undefined;\r\n this.size = 0;\r\n this._container.clear();\r\n }\r\n\r\n /** Returns an iterator over all keys, starting with the oldest. */\r\n public keys(): Iterator<K | undefined> | undefined {\r\n return this.oldest ? new KeyIterator(this.oldest) : undefined;\r\n }\r\n\r\n /** Returns an iterator over all values, starting with the oldest. */\r\n public values(): Iterator<V | undefined> | undefined {\r\n return this.oldest ? new ValueIterator(this.oldest) : undefined;\r\n }\r\n\r\n /** Returns an iterator over all entries, starting with the oldest. */\r\n public entries(): Iterator<[K, V] | undefined> | undefined {\r\n return this.oldest ? new EntryIterator(this.oldest) : undefined;\r\n }\r\n\r\n /** Call `fun` for each entry, starting with the oldest entry. */\r\n public forEach(fun: (value: V, key: K, m: LRUCache<K, V>) => void, thisObj?: any): void {\r\n if (typeof thisObj !== \"object\") {\r\n thisObj = this;\r\n }\r\n let entry = this.oldest;\r\n while (entry) {\r\n fun.call(thisObj, entry.value, entry.key, this);\r\n entry = entry.newer;\r\n }\r\n }\r\n\r\n /** Returns a JSON (array) representation */\r\n public toJSON(): Array<{ key: K, value: V }> {\r\n const s = new Array(this.size);\r\n let i = 0;\r\n let entry = this.oldest;\r\n while (entry) {\r\n s[i++] = { key: entry.key, value: entry.value };\r\n entry = entry.newer;\r\n }\r\n return s;\r\n }\r\n\r\n /** Returns a String representation */\r\n public toString(): string {\r\n let s = \"\";\r\n let entry = this.oldest;\r\n while (entry) {\r\n s += `${String(entry.key)}:${entry.value}`;\r\n entry = entry.newer;\r\n if (entry) {\r\n s += \" < \";\r\n }\r\n }\r\n return s;\r\n }\r\n}\r\n\r\n/** A [[LRUCache]] using a standard Map as its internal storage.\r\n * @public\r\n */\r\nexport class LRUMap<K, V> extends LRUCache<K, V> {\r\n /**\r\n * Construct a new LRUMap to hold up to `limit` entries.\r\n */\r\n constructor(limit: number) {\r\n super(limit, new Map<K, Entry<K, V>>());\r\n }\r\n}\r\n\r\n/** A [[LRUCache]] using a [[Dictionary]] as its internal storage, permitting custom key comparison logic.\r\n * @public\r\n */\r\nexport class LRUDictionary<K, V> extends LRUCache<K, V> {\r\n /**\r\n * Construct a new LRUDictionary to hold up to `limit` entries.\r\n * @param limit The maximum number of entries permitted in the dictionary.\r\n * @param compareKeys The function used to compare keys within the dictionary.\r\n */\r\n constructor(limit: number, compareKeys: OrderedComparator<K>) {\r\n super(limit, new Dictionary<K, Entry<K, V>>(compareKeys));\r\n }\r\n}\r\n"]}
1
+ {"version":3,"file":"LRUMap.js","sourceRoot":"","sources":["../../src/LRUMap.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAGH,6CAA0C;AAE1C;;;;GAIG;AAEH;;GAEG;AACH,MAAa,KAAK;IAGhB,YAAmB,GAAM,EAAS,KAAQ;QAAvB,QAAG,GAAH,GAAG,CAA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AG,EAAkB,CAAC,CAAC;IAC1C,CAAC;CACF;AAPD,wBAOC;AAED;;GAEG;AACH,MAAa,aAAoB,SAAQ,QAAc;IACrD;;;;OAIG;IACH,YAAY,KAAa,EAAE,WAAiC;QAC1D,KAAK,CAAC,KAAK,EAAE,IAAI,uBAAU,CAAiB,WAAW,CAAC,CAAC,CAAC;IAC5D,CAAC;CACF;AATD,sCASC","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n/** @packageDocumentation\r\n * @module Collections\r\n */\r\n\r\nimport { OrderedComparator } from \"./Compare\";\r\nimport { Dictionary } from \"./Dictionary\";\r\n\r\n/**\r\n * Derived from:\r\n * Licensed under MIT. Copyright (c) 2010 Rasmus Andersson <http://hunch.se/>\r\n * See README.md at https://github.com/rsms/js-lru for details.\r\n */\r\n\r\n/** An entry holds the key and value, and pointers to any older and newer entries.\r\n * @public\r\n */\r\nexport class Entry<K, V> {\r\n public newer?: Entry<K, V>;\r\n public older?: Entry<K, V>;\r\n constructor(public key: K, public value: V) { }\r\n}\r\n\r\nclass EntryIterator<K, V> implements Iterator<[K, V] | undefined> {\r\n private _entry: Entry<K, V> | undefined;\r\n constructor(oldestEntry: Entry<K, V>) {\r\n this._entry = oldestEntry;\r\n }\r\n public next() {\r\n const ent = this._entry;\r\n if (!ent)\r\n return { done: true, value: undefined };\r\n this._entry = ent.newer;\r\n const val: [K, V] = [ent.key, ent.value];\r\n return { done: false, value: val };\r\n }\r\n}\r\n\r\nclass KeyIterator<K, V> implements Iterator<K | undefined> {\r\n private _entry: Entry<K, V> | undefined;\r\n constructor(oldestEntry: Entry<K, V>) {\r\n this._entry = oldestEntry;\r\n }\r\n public next() {\r\n const ent = this._entry;\r\n if (!ent)\r\n return { done: true, value: undefined };\r\n this._entry = ent.newer;\r\n return { done: false, value: ent.key };\r\n }\r\n}\r\n\r\nclass ValueIterator<K, V> implements Iterator<V | undefined> {\r\n private _entry: Entry<K, V> | undefined;\r\n constructor(oldestEntry: Entry<K, V>) {\r\n this._entry = oldestEntry;\r\n }\r\n public next() {\r\n const ent = this._entry;\r\n if (!ent)\r\n return { done: true, value: undefined };\r\n this._entry = ent.newer;\r\n return { done: false, value: ent.value };\r\n }\r\n}\r\n\r\n/** The interface that must be satisfied by the underlying container type used by a LRUCache.\r\n * Compatible with a [[Dictionary]] or a standard Map.\r\n * @public\r\n */\r\nexport interface EntryContainer<K, V> {\r\n readonly size: number;\r\n clear(): void;\r\n get(key: K): Entry<K, V> | undefined;\r\n set(key: K, value: Entry<K, V>): void;\r\n has(key: K): boolean;\r\n delete(key: K): void;\r\n}\r\n\r\n/**\r\n * A mapping of a key/value pairs, where the size of the cache can be limited.\r\n *\r\n * When entries are inserted, if the cache is \"full\", the\r\n * least-recently-used (LRU) value is dropped. When entries are retrieved, they are moved to the front of the LRU list.\r\n *\r\n * Illustration of the design:\r\n *\r\n * ```\r\n *\r\n * entry entry entry entry\r\n * ______ ______ ______ ______\r\n * | head |.newer => | |.newer => | |.newer => | tail |\r\n * | A | | B | | C | | D |\r\n * |______| <= older.|______| <= older.|______| <= older.|______|\r\n *\r\n * removed <-- <-- <-- <-- <-- <-- <-- <-- <-- <-- <-- added\r\n * ```\r\n * @public\r\n */\r\nexport class LRUCache<K, V> {\r\n private _container: EntryContainer<K, V>;\r\n\r\n /** Current number of items */\r\n public size: number;\r\n\r\n /** Maximum number of items this cache can hold */\r\n public limit: number;\r\n\r\n /** Least recently-used entry. Invalidated when cache is modified. */\r\n public oldest?: Entry<K, V>;\r\n\r\n /** Most recently-used entry. Invalidated when cache is modified. */\r\n public newest?: Entry<K, V>;\r\n\r\n /**\r\n * Construct a new LRUCache to hold up to `limit` entries.\r\n */\r\n public constructor(limit: number, container: EntryContainer<K, V>) {\r\n this.size = 0;\r\n this.limit = limit;\r\n this.oldest = this.newest = undefined;\r\n this._container = container;\r\n }\r\n\r\n private markEntryAsUsed(entry: Entry<K, V>) {\r\n if (entry === this.newest)\r\n return; // Already the most recently used entry, so no need to update the list\r\n\r\n // HEAD--------------TAIL\r\n // <.older .newer>\r\n // <--- add direction --\r\n // A B C <D> E\r\n if (entry.newer) {\r\n if (entry === this.oldest) {\r\n this.oldest = entry.newer;\r\n }\r\n entry.newer.older = entry.older; // C <-- E.\r\n }\r\n if (entry.older) {\r\n entry.older.newer = entry.newer; // C. --> E\r\n }\r\n entry.newer = undefined; // D --x\r\n entry.older = this.newest; // D. --> E\r\n if (this.newest) {\r\n this.newest.newer = entry; // E. <-- D\r\n }\r\n this.newest = entry;\r\n }\r\n\r\n /** Replace all values in this cache with key-value pairs (2-element Arrays) from provided iterable. */\r\n public assign(entries: Iterable<[K, V]>): void {\r\n let entry;\r\n let limit = this.limit || Number.MAX_VALUE;\r\n this._container.clear();\r\n const it = entries[Symbol.iterator]();\r\n for (let itv = it.next(); !itv.done; itv = it.next()) {\r\n const e = new Entry(itv.value[0], itv.value[1]);\r\n this._container.set(e.key, e);\r\n if (!entry) {\r\n this.oldest = e;\r\n } else {\r\n entry.newer = e;\r\n e.older = entry;\r\n }\r\n entry = e;\r\n if (limit-- === 0) {\r\n throw new Error(\"overflow\");\r\n }\r\n }\r\n this.newest = entry;\r\n this.size = this._container.size;\r\n }\r\n\r\n /** Get and register recent use of <key>.\r\n * Returns the value associated with <key> or undefined if not in cache.\r\n */\r\n public get(key: K): V | undefined {\r\n // First, find our cache entry\r\n const entry = this._container.get(key);\r\n if (!entry)\r\n return; // Not cached. Sorry.\r\n // As <key> was found in the cache, register it as being requested recently\r\n this.markEntryAsUsed(entry);\r\n return entry.value;\r\n }\r\n\r\n /** Put <value> into the cache associated with <key>. Replaces any existing entry with the same key.\r\n * @returns `this`.\r\n */\r\n public set(key: K, value: V): LRUCache<K, V> {\r\n let entry = this._container.get(key);\r\n if (entry) {\r\n // update existing\r\n entry.value = value;\r\n this.markEntryAsUsed(entry);\r\n return this;\r\n }\r\n\r\n // new entry\r\n this._container.set(key, (entry = new Entry(key, value)));\r\n\r\n if (this.newest) {\r\n // link previous tail to the new tail (entry)\r\n this.newest.newer = entry;\r\n entry.older = this.newest;\r\n } else {\r\n // we're first in\r\n this.oldest = entry;\r\n }\r\n\r\n // add new entry to the end of the linked list -- it is now the freshest entry.\r\n this.newest = entry;\r\n ++this.size;\r\n if (this.size > this.limit) {\r\n // we hit the limit -- remove the head\r\n this.shift();\r\n }\r\n return this;\r\n }\r\n\r\n /** Purge the least recently used (oldest) entry from the cache.\r\n * @returns The removed entry or undefined if the cache was empty.\r\n */\r\n public shift(): [K, V] | undefined {\r\n const entry = this.oldest;\r\n if (entry) {\r\n if (entry.newer) {\r\n // advance the list\r\n this.oldest = entry.newer;\r\n this.oldest.older = undefined;\r\n } else {\r\n // the cache is exhausted\r\n this.oldest = undefined;\r\n this.newest = undefined;\r\n }\r\n // Remove last strong reference to <entry> and remove links from the purged\r\n // entry being returned:\r\n entry.newer = entry.older = undefined;\r\n this._container.delete(entry.key);\r\n --this.size;\r\n return [entry.key, entry.value];\r\n }\r\n return undefined;\r\n }\r\n\r\n /** Access value for `key` without registering recent use. Useful if you do not\r\n * want to change the state of the cache, but only \"peek\" at it.\r\n * @returns The value associated with `key` if found, or undefined if not found.\r\n */\r\n public find(key: K): V | undefined {\r\n const e = this._container.get(key);\r\n return e ? e.value : undefined;\r\n }\r\n\r\n /** Check if there's a value for key in the cache without registering recent use. */\r\n public has(key: K): boolean {\r\n return this._container.has(key);\r\n }\r\n\r\n /** Remove entry `key` from cache and return its value.\r\n * @returns The removed value, or undefined if not found.\r\n */\r\n public delete(key: K): V | undefined {\r\n const entry = this._container.get(key);\r\n if (!entry)\r\n return;\r\n\r\n this._container.delete(entry.key);\r\n if (entry.newer && entry.older) {\r\n // re-link the older entry with the newer entry\r\n entry.older.newer = entry.newer;\r\n entry.newer.older = entry.older;\r\n } else if (entry.newer) {\r\n // remove the link to us\r\n entry.newer.older = undefined;\r\n // link the newer entry to head\r\n this.oldest = entry.newer;\r\n } else if (entry.older) {\r\n // remove the link to us\r\n entry.older.newer = undefined;\r\n // link the newer entry to head\r\n this.newest = entry.older;\r\n } else { // if(entry.older === undefined && entry.newer === undefined) {\r\n this.oldest = this.newest = undefined;\r\n }\r\n\r\n this.size--;\r\n return entry.value;\r\n }\r\n\r\n /** Removes all entries */\r\n public clear(): void {\r\n // Note: clearing links should be safe, as we don't expose live links to user\r\n this.oldest = this.newest = undefined;\r\n this.size = 0;\r\n this._container.clear();\r\n }\r\n\r\n /** Returns an iterator over all keys, starting with the oldest. */\r\n public keys(): Iterator<K | undefined> | undefined {\r\n return this.oldest ? new KeyIterator(this.oldest) : undefined;\r\n }\r\n\r\n /** Returns an iterator over all values, starting with the oldest. */\r\n public values(): Iterator<V | undefined> | undefined {\r\n return this.oldest ? new ValueIterator(this.oldest) : undefined;\r\n }\r\n\r\n /** Returns an iterator over all entries, starting with the oldest. */\r\n public entries(): Iterator<[K, V] | undefined> | undefined {\r\n return this.oldest ? new EntryIterator(this.oldest) : undefined;\r\n }\r\n\r\n /** Call `fun` for each entry, starting with the oldest entry. */\r\n public forEach(fun: (value: V, key: K, m: LRUCache<K, V>) => void, thisObj?: any): void {\r\n if (typeof thisObj !== \"object\") {\r\n thisObj = this;\r\n }\r\n let entry = this.oldest;\r\n while (entry) {\r\n fun.call(thisObj, entry.value, entry.key, this);\r\n entry = entry.newer;\r\n }\r\n }\r\n\r\n /** Returns a JSON (array) representation */\r\n public toJSON(): Array<{ key: K, value: V }> {\r\n const s = new Array(this.size);\r\n let i = 0;\r\n let entry = this.oldest;\r\n while (entry) {\r\n s[i++] = { key: entry.key, value: entry.value };\r\n entry = entry.newer;\r\n }\r\n return s;\r\n }\r\n\r\n /** Returns a String representation */\r\n public toString(): string {\r\n let s = \"\";\r\n let entry = this.oldest;\r\n while (entry) {\r\n s += `${String(entry.key)}:${entry.value}`;\r\n entry = entry.newer;\r\n if (entry) {\r\n s += \" < \";\r\n }\r\n }\r\n return s;\r\n }\r\n}\r\n\r\n/** A [[LRUCache]] using a standard Map as its internal storage.\r\n * @public\r\n */\r\nexport class LRUMap<K, V> extends LRUCache<K, V> {\r\n /**\r\n * Construct a new LRUMap to hold up to `limit` entries.\r\n */\r\n constructor(limit: number) {\r\n super(limit, new Map<K, Entry<K, V>>());\r\n }\r\n}\r\n\r\n/** A [[LRUCache]] using a [[Dictionary]] as its internal storage, permitting custom key comparison logic.\r\n * @public\r\n */\r\nexport class LRUDictionary<K, V> extends LRUCache<K, V> {\r\n /**\r\n * Construct a new LRUDictionary to hold up to `limit` entries.\r\n * @param limit The maximum number of entries permitted in the dictionary.\r\n * @param compareKeys The function used to compare keys within the dictionary.\r\n */\r\n constructor(limit: number, compareKeys: OrderedComparator<K>) {\r\n super(limit, new Dictionary<K, Entry<K, V>>(compareKeys));\r\n }\r\n}\r\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"OneAtATimeAction.d.ts","sourceRoot":"","sources":["../../src/OneAtATimeAction.ts"],"names":[],"mappings":"AAIA;;GAEG;AAIH,YAAY;AACZ,qBAAa,cAAe,SAAQ,KAAK;CAAI;AAqC7C;;;;;;;;;;GAUG;AACH,qBAAa,gBAAgB,CAAC,CAAC;IAC7B,OAAO,CAAC,OAAO,CAAC,CAAwB;IACxC,OAAO,CAAC,QAAQ,CAAC,CAAwB;IACzC,OAAO,CAAC,IAAI,CAAiC;IACtC,GAAG,EAAE,MAAM,CAAC;IAEnB;;OAEG;gBACS,GAAG,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,OAAO,CAAC,CAAC,CAAC,EAAE,GAAG,SAAc;IAElE;;OAEG;IACU,OAAO,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,GAAG,OAAO,CAAC,CAAC,CAAC;CAuBjD"}
1
+ {"version":3,"file":"OneAtATimeAction.d.ts","sourceRoot":"","sources":["../../src/OneAtATimeAction.ts"],"names":[],"mappings":"AAIA;;GAEG;AAIH,YAAY;AACZ,qBAAa,cAAe,SAAQ,KAAK;CAAI;AAqC7C;;;;;;;;;;GAUG;AACH,qBAAa,gBAAgB,CAAC,CAAC;IAC7B,OAAO,CAAC,OAAO,CAAC,CAAwB;IACxC,OAAO,CAAC,QAAQ,CAAC,CAAwB;IACzC,OAAO,CAAC,IAAI,CAAiC;IACtC,GAAG,EAAE,MAAM,CAAC;IAEnB;;OAEG;gBACS,GAAG,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,OAAO,CAAC,CAAC,CAAC,EAAE,GAAG,SAAc;IAKlE;;OAEG;IACU,OAAO,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,GAAG,OAAO,CAAC,CAAC,CAAC;CAuBjD"}
@@ -60,7 +60,10 @@ class OneAtATimeAction {
60
60
  /** Ctor for OneAtATimePromise.
61
61
  * @param run The method that performs an action that creates the Promise.
62
62
  */
63
- constructor(run, msg = "abandoned") { this._run = run; this.msg = msg; }
63
+ constructor(run, msg = "abandoned") {
64
+ this._run = run;
65
+ this.msg = msg;
66
+ }
64
67
  /** Add a new request to this OneAtATimePromise. The request will only run when no other outstanding requests are active.
65
68
  * @note Callers of this method *must* handle AbandonedError rejections.
66
69
  */
@@ -1 +1 @@
1
- {"version":3,"file":"OneAtATimeAction.js","sourceRoot":"","sources":["../../src/OneAtATimeAction.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,iDAA8C;AAE9C,YAAY;AACZ,MAAa,cAAe,SAAQ,KAAK;CAAI;AAA7C,wCAA6C;AAE7C;;;;;GAKG;AACH,MAAM,kBAAkB;IAKtB;;;OAGG;IACH,YAAoB,IAAoC,EAAU,KAAY;QAA1D,SAAI,GAAJ,IAAI,CAAgC;QAAU,UAAK,GAAL,KAAK,CAAO;IAAI,CAAC;IAEnF,0GAA0G;IACnG,KAAK,CAAC,IAAI,CAAC,GAAW;QAC3B,OAAO,IAAI,OAAO,CAAI,CAAC,OAAO,EAAE,M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I,CAAC,OAAO,GAAG,KAAK,CAAC,CAAC,uCAAuC;YAC7D,KAAK,CAAC,KAAK,EAAE,CAAC,CAAC,8DAA8D;SAC9E;QAED,IAAI;YACF,OAAO,MAAM,OAAO,CAAC;SACtB;gBAAS;YACR,2DAA2D;YAC3D,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,QAAQ,CAAC,CAAC,2CAA2C;YACzE,IAAI,CAAC,QAAQ,GAAG,SAAS,CAAC,CAAC,gBAAgB;YAC3C,IAAI,IAAI,CAAC,OAAO;gBACd,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC,CAAC,8DAA8D;SACvF;IACH,CAAC;CACF;AArCD,4CAqCC","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n/** @packageDocumentation\r\n * @module Utils\r\n */\r\n\r\nimport { BentleyError } from \"./BentleyError\";\r\n\r\n/** @beta */\r\nexport class AbandonedError extends Error { }\r\n\r\n/**\r\n * An object that returns a Promise when you call [[init]], but supplies a way to abandon the promise if it is no longer relevant.\r\n * When you call abandon, the promise will be rejected. You must supply a [[run]] method to the constructor that\r\n * creates the real Promise for the underlying action. Notice that to use this class there are really two\r\n * Promises involved that are chained together. That makes this class less efficient than just using a Promise directly.\r\n */\r\nclass PromiseWithAbandon<T> {\r\n /** Method to abandon the Promise created by [[init]] while it is outstanding. The promise will be rejected. */\r\n public abandon!: (msg?: string) => void;\r\n private _resolve!: (val: any) => void;\r\n\r\n /** Create a PromiseWithAbandon. After this call you must call [[init]] to create the underlying Promise.\r\n * @param _run The method that creates the underlying Promise.\r\n * @param _args An array of args to be passed to run when [[start]] is called.\r\n */\r\n constructor(private _run: (...args: any[]) => Promise<T>, private _args: any[]) { }\r\n\r\n /** Create a Promise that is chained to the underlying Promise, but is connected to the abandon method. */\r\n public async init(msg: string): Promise<T> {\r\n return new Promise<T>((resolve, reject) => {\r\n this.abandon = (message?: string) => reject(new AbandonedError(message ?? msg));\r\n this._resolve = resolve;\r\n });\r\n }\r\n\r\n /** Call the [[run]] method supplied to the ctor to start the underlying Promise. */\r\n public async start() {\r\n try {\r\n this._resolve(await this._run(...this._args));\r\n } catch (err) {\r\n this.abandon(BentleyError.getErrorMessage(err)); // turn all errors from execution into abandoned errors, but keep the message\r\n }\r\n }\r\n}\r\n\r\n/**\r\n * Orchestrator of a one-at-a-time activity. This concept is useful only for *replaceable* operations (that is, operations where subsequent requests replace and obviate\r\n * the need for previous requests. E.g. over slow HTTP connections, without this class, the stream of requests can overwhelm the connection, and cause the HTTP\r\n * request queue to grow such that the delay to service new requests is unbounded.\r\n *\r\n * With this class, we issue the initial request immediately. When the second request arrives before the first one completes, it becomes *pending*. If subsequent\r\n * requests arrive with a pending request, the current pending request is *abandoned* (its Promise is rejected) and the new request becomes pending.\r\n * When the active request completes, the pending request (if present) is started. In this manner there will only ever be one outstanding HTTP request for this type\r\n * of operation, but the first and last request will always eventually complete.\r\n * @beta\r\n */\r\nexport class OneAtATimeAction<T> {\r\n private _active?: PromiseWithAbandon<T>;\r\n private _pending?: PromiseWithAbandon<T>;\r\n private _run: (...args: any[]) => Promise<T>;\r\n public msg: string;\r\n\r\n /** Ctor for OneAtATimePromise.\r\n * @param run The method that performs an action that creates the Promise.\r\n */\r\n constructor(run: (...args: any[]) => Promise<T>, msg = \"abandoned\") { this._run = run; this.msg = msg; }\r\n\r\n /** Add a new request to this OneAtATimePromise. The request will only run when no other outstanding requests are active.\r\n * @note Callers of this method *must* handle AbandonedError rejections.\r\n */\r\n public async request(...args: any[]): Promise<T> {\r\n const entry = new PromiseWithAbandon<T>(this._run, args); // create an \"abandon-able promise\" object\r\n const promise = entry.init(this.msg); // create the Promise from PromiseWithAbandon. Note: this must be called before we call start.\r\n\r\n if (this._active !== undefined) { // is there an active request?\r\n if (this._pending) // yes. If there is also a pending request, this one replaces it and previous one is abandoned\r\n this._pending.abandon(); // rejects previous call to this method, throwing AbandonedError.\r\n this._pending = entry;\r\n } else {\r\n this._active = entry; // this is the first request, start it.\r\n entry.start(); // eslint-disable-line @typescript-eslint/no-floating-promises\r\n }\r\n\r\n try {\r\n return await promise;\r\n } finally {\r\n // do all of this whether promise was fulfilled or rejected\r\n this._active = this._pending; // see if there's a pending request waiting\r\n this._pending = undefined; // clear pending\r\n if (this._active)\r\n this._active.start(); // eslint-disable-line @typescript-eslint/no-floating-promises\r\n }\r\n }\r\n}\r\n"]}
1
+ {"version":3,"file":"OneAtATimeAction.js","sourceRoot":"","sources":["../../src/OneAtATimeAction.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,iDAA8C;AAE9C,YAAY;AACZ,MAAa,cAAe,SAAQ,KAAK;CAAI;AAA7C,wCAA6C;AAE7C;;;;;GAKG;AACH,MAAM,kBAAkB;IAKtB;;;OAGG;IACH,YAAoB,IAAoC,EAAU,KAAY;QAA1D,SAAI,GAAJ,IAAI,CAAgC;QAAU,UAAK,GAAL,KAAK,CAAO;IAAI,CAAC;IAEnF,0GAA0G;IACnG,KAAK,CAAC,IAAI,CAAC,GAAW;QAC3B,OAAO,IAAI,OAAO,CAAI,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;YACxC,IAAI,CAAC,OAAO,GAAG,CAAC,OAAgB,EAAE,EAAE,CAAC,MAAM,CAAC,IAAI,cAAc,CAAC,OAAO,aAAP,OAAO,cAAP,OAAO,GAAI,GAAG,CAAC,CAAC,CAAC;YAChF,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC;QAC1B,CAAC,CAAC,CAAC;IACL,CAAC;IAED,oFAAoF;IAC7E,KAAK,CAAC,KAAK;QAChB,IAAI;YACF,IAAI,CAAC,QAAQ,CAAC,MAAM,IAAI,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC;SAC/C;QAAC,OAAO,GAAG,EAAE;YACZ,IA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/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n/** @packageDocumentation\r\n * @module Utils\r\n */\r\n\r\nimport { BentleyError } from \"./BentleyError\";\r\n\r\n/** @beta */\r\nexport class AbandonedError extends Error { }\r\n\r\n/**\r\n * An object that returns a Promise when you call [[init]], but supplies a way to abandon the promise if it is no longer relevant.\r\n * When you call abandon, the promise will be rejected. You must supply a [[run]] method to the constructor that\r\n * creates the real Promise for the underlying action. Notice that to use this class there are really two\r\n * Promises involved that are chained together. That makes this class less efficient than just using a Promise directly.\r\n */\r\nclass PromiseWithAbandon<T> {\r\n /** Method to abandon the Promise created by [[init]] while it is outstanding. The promise will be rejected. */\r\n public abandon!: (msg?: string) => void;\r\n private _resolve!: (val: any) => void;\r\n\r\n /** Create a PromiseWithAbandon. After this call you must call [[init]] to create the underlying Promise.\r\n * @param _run The method that creates the underlying Promise.\r\n * @param _args An array of args to be passed to run when [[start]] is called.\r\n */\r\n constructor(private _run: (...args: any[]) => Promise<T>, private _args: any[]) { }\r\n\r\n /** Create a Promise that is chained to the underlying Promise, but is connected to the abandon method. */\r\n public async init(msg: string): Promise<T> {\r\n return new Promise<T>((resolve, reject) => {\r\n this.abandon = (message?: string) => reject(new AbandonedError(message ?? msg));\r\n this._resolve = resolve;\r\n });\r\n }\r\n\r\n /** Call the [[run]] method supplied to the ctor to start the underlying Promise. */\r\n public async start() {\r\n try {\r\n this._resolve(await this._run(...this._args));\r\n } catch (err) {\r\n this.abandon(BentleyError.getErrorMessage(err)); // turn all errors from execution into abandoned errors, but keep the message\r\n }\r\n }\r\n}\r\n\r\n/**\r\n * Orchestrator of a one-at-a-time activity. This concept is useful only for *replaceable* operations (that is, operations where subsequent requests replace and obviate\r\n * the need for previous requests. E.g. over slow HTTP connections, without this class, the stream of requests can overwhelm the connection, and cause the HTTP\r\n * request queue to grow such that the delay to service new requests is unbounded.\r\n *\r\n * With this class, we issue the initial request immediately. When the second request arrives before the first one completes, it becomes *pending*. If subsequent\r\n * requests arrive with a pending request, the current pending request is *abandoned* (its Promise is rejected) and the new request becomes pending.\r\n * When the active request completes, the pending request (if present) is started. In this manner there will only ever be one outstanding HTTP request for this type\r\n * of operation, but the first and last request will always eventually complete.\r\n * @beta\r\n */\r\nexport class OneAtATimeAction<T> {\r\n private _active?: PromiseWithAbandon<T>;\r\n private _pending?: PromiseWithAbandon<T>;\r\n private _run: (...args: any[]) => Promise<T>;\r\n public msg: string;\r\n\r\n /** Ctor for OneAtATimePromise.\r\n * @param run The method that performs an action that creates the Promise.\r\n */\r\n constructor(run: (...args: any[]) => Promise<T>, msg = \"abandoned\") {\r\n this._run = run;\r\n this.msg = msg;\r\n }\r\n\r\n /** Add a new request to this OneAtATimePromise. The request will only run when no other outstanding requests are active.\r\n * @note Callers of this method *must* handle AbandonedError rejections.\r\n */\r\n public async request(...args: any[]): Promise<T> {\r\n const entry = new PromiseWithAbandon<T>(this._run, args); // create an \"abandon-able promise\" object\r\n const promise = entry.init(this.msg); // create the Promise from PromiseWithAbandon. Note: this must be called before we call start.\r\n\r\n if (this._active !== undefined) { // is there an active request?\r\n if (this._pending) // yes. If there is also a pending request, this one replaces it and previous one is abandoned\r\n this._pending.abandon(); // rejects previous call to this method, throwing AbandonedError.\r\n this._pending = entry;\r\n } else {\r\n this._active = entry; // this is the first request, start it.\r\n entry.start(); // eslint-disable-line @typescript-eslint/no-floating-promises\r\n }\r\n\r\n try {\r\n return await promise;\r\n } finally {\r\n // do all of this whether promise was fulfilled or rejected\r\n this._active = this._pending; // see if there's a pending request waiting\r\n this._pending = undefined; // clear pending\r\n if (this._active)\r\n this._active.start(); // eslint-disable-line @typescript-eslint/no-floating-promises\r\n }\r\n }\r\n}\r\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"SortedArray.d.ts","sourceRoot":"","sources":["../../src/SortedArray.ts"],"names":[],"mappings":"AAI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AG,IAAI;IAK9C;;;;OAIG;IACH,SAAS,CAAC,UAAU,CAAC,KAAK,EAAE,CAAC,GAAG;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,OAAO,CAAA;KAAE;IAEjE,+CAA+C;IAC/C,SAAS,CAAC,MAAM,IAAI,IAAI;IAExB;;OAEG;IACH,SAAS,CAAC,aAAa,IAAI,CAAC,EAAE;IAM9B;;;;;;;;;;;;;;;;OAgBG;IACH,SAAS,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC,EAAE,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,GAAG,GAAG,MAAM;IAuBjE;;;;OAIG;IACH,SAAS,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC,GAAG,MAAM;CASpC;AAED;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,qBAAa,WAAW,CAAC,CAAC,CAAE,SAAQ,mBAAmB,CAAC,CAAC,CAAC;IACxD;;;;;OAKG;gBACgB,OAAO,EAAE,iBAAiB,CAAC,CAAC,CAAC,EAAE,eAAe,GAAE,eAAe,GAAG,OAAe,EAAE,KAAK,GAAE,aAAa,CAAC,CAAC,CAAgB;IAI5I,+CAA+C;IACxC,KAAK,IAAI,IAAI;IAEpB;;OAEG;IACI,YAAY,IAAI,CAAC,EAAE;IAE1B;;;;;;;;;;;;;;OAcG;IACI,MAAM,CAAC,KAAK,EAAE,CAAC,EAAE,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,GAAG,GAAG,MAAM;IAE7D;;;;OAIG;IACI,MAAM,CAAC,KAAK,EAAE,CAAC,GAAG,MAAM;CAChC"}
@@ -15,7 +15,9 @@ exports.SortedArray = exports.ReadonlySortedArray = exports.DuplicatePolicy = ex
15
15
  * @returns the input value.
16
16
  * @public
17
17
  */
18
- function shallowClone(value) { return value; }
18
+ function shallowClone(value) {
19
+ return value;
20
+ }
19
21
  exports.shallowClone = shallowClone;
20
22
  /**
21
23
  * Given a sorted array, computes the position at which the specified value should be inserted into the array so that the array remains sorted.
@@ -1 +1 @@
1
- {"version":3,"file":"SortedArray.js","sourceRoot":"","sources":["../../src/SortedArray.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAWH;;;;;;GAMG;AACH,SAAgB,YAAY,CAAI,KAAQ,IAAI,OAAO,KAAK,CAAC,CAAC,CAAC;AAA3D,oCAA2D;AAE3D;;;;;;;GAOG;AACH,SAAgB,UAAU,CAAW,KAAQ,EAAE,IAAS,EAAE,OAAgC;IACxF,OAAO,sBAAsB,CAAC,IAAI,EAAE,CAAC,OAAU,EAAE,EAAE,CAAC,OAAO,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC,CAAC;AAC/E,CAAC;AAFD,gCAEC;AAED,SAAS,sBAAsB,CAAI,IAAS,EAAE,SAAiC;IAC7E,IAAI,GAAG,GAAG,CAAC,CAAC;IACZ,IAAI,IAAI,GAAG,IAAI,CAAC,MAAM,CAAC;IACvB,OAAO,GAAG,GAAG,IAAI,EAAE;QACjB,MAAM,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,GAAG,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;QACzC,MAAM,IAAI,GAAG,SAAS,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;QAClC,IAAI,CAAC,KAAK,IAAI;YACZ,OAAO,EAAE,KAAK,EAAE,GAAG,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;aAChC,IAAI,IAAI,GAAG,CAAC;YACf,IAAI,GAAG,GAAG,CAAC;;YAEX,GAAG,GAAG,GAAG,GAAG,CAAC,CAAC;KACjB;IAED,OAAO,EAAE,KAAK,EAAE,GAAG,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC;AACtC,CAAC;AAED;;;GAGG;AACH,IAAY,eAWX;AAXD,WAAY,eAAe;IACzB;;OAEG;IACH,uDAAK,CAAA;IACL,mJAAmJ;IACnJ,yDAAM,CAA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M,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;YACnC,OAAO,KAAK,CAAC,KAAK,CAAC;SACpB;aAAM;YACL,OAAO,CAAC,CAAC,CAAC;SACX;IACH,CAAC;CACF;AA7KD,kDA6KC;AAED;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,MAAa,WAAe,SAAQ,mBAAsB;IACxD;;;;;OAKG;IACH,YAAmB,OAA6B,EAAE,kBAA6C,KAAK,EAAE,QAA0B,YAAY;QAC1I,KAAK,CAAC,OAAO,EAAE,eAAe,EAAE,KAAK,CAAC,CAAC;IACzC,CAAC;IAED,+CAA+C;IACxC,KAAK,KAAW,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC;IAEvC;;OAEG;IACI,YAAY,KAAU,OAAO,IAAI,CAAC,aAAa,EAAE,CAAC,CAAC,CAAC;IAE3D;;;;;;;;;;;;;;OAcG;IACI,MAAM,CAAC,KAAQ,EAAE,QAA4B,IAAY,OAAO,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC;IAEvG;;;;OAIG;IACI,MAAM,CAAC,KAAQ,IAAY,OAAO,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;CAChE;AA1CD,kCA0CC","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n/** @packageDocumentation\r\n * @module Collections\r\n */\r\n\r\nimport { OrderedComparator } from \"./Compare\";\r\n\r\n/**\r\n * A function that, given a value of type T, returns a copy of that value. Such functions are used by various collection classes.\r\n * It is up to the function to decide how deeply or shallowly the value is cloned. For example, [[shallowClone]] simply returns the input.\r\n * @public\r\n */\r\nexport type CloneFunction<T> = (value: T) => T;\r\n\r\n/**\r\n * A [[CloneFunction]] that, given a value of type T, returns the same value.\r\n * Useful as a default argument for functions that can alternatively accept custom logic for cloning values of object type.\r\n * @param value The value to clone.\r\n * @returns the input value.\r\n * @public\r\n */\r\nexport function shallowClone<T>(value: T) { return value; }\r\n\r\n/**\r\n * Given a sorted array, computes the position at which the specified value should be inserted into the array so that the array remains sorted.\r\n * @param value The value whose position is to be computed.\r\n * @param list An array of U already sorted according to the comparison criterion.\r\n * @param compare The function used to compare the value with elements in `list`.\r\n * @returns an object with 'index' corresponding to the computed position and 'equal' set to true if an equivalent element already exists at that index.\r\n * @public\r\n */\r\nexport function lowerBound<T, U = T>(value: T, list: U[], compare: OrderedComparator<T, U>): { index: number, equal: boolean } {\r\n return lowerBoundOfEquivalent(list, (element: U) => compare(value, element));\r\n}\r\n\r\nfunction lowerBoundOfEquivalent<T>(list: T[], criterion: (element: T) => number): { index: number, equal: boolean } {\r\n let low = 0;\r\n let high = list.length;\r\n while (low < high) {\r\n const mid = Math.floor((low + high) / 2);\r\n const comp = criterion(list[mid]);\r\n if (0 === comp)\r\n return { index: mid, equal: true };\r\n else if (comp < 0)\r\n high = mid;\r\n else\r\n low = mid + 1;\r\n }\r\n\r\n return { index: low, equal: false };\r\n}\r\n\r\n/** Describes how duplicate values are handled when inserting into a [[SortedArray]].\r\n * A \"duplicate\" value is one that compares equal to a value already present in the array, per the array's comparison function.\r\n * @public\r\n */\r\nexport enum DuplicatePolicy {\r\n /** The array allows duplicate values to be inserted. All duplicate values will be adjacent in the array, but the ordering between duplicate values is unspecified.\r\n * @note In the presence of duplicate values, functions like [[SortedArray.indexOf]] and [[SortedArray.findEqual]] will return one of the values - exactly which one is unspecified.\r\n */\r\n Allow,\r\n /** Duplicate values are forbidden - when attempting to insert a value equivalent to one already present, the already-present value is retained. */\r\n Retain,\r\n /** Duplicate values are forbidden - when attempting to insert a value equivalent to one already present, the already-present value is replaced by the new value.\r\n * This can be useful when the value type carries additional data that is not evaluated by the comparison function.\r\n */\r\n Replace,\r\n}\r\n\r\n/**\r\n * A read-only view of an array of some type T sorted according to some user-supplied criterion.\r\n * Duplicate elements may be present, though sub-types may enforce uniqueness of elements.\r\n * In the absence of duplicates, a ReadonlySortedArray<T> can behave like a Set<T> where T is an object and equality is determined\r\n * by some criterion other than object identity.\r\n *\r\n * Because the array is always sorted, querying for the presence of an element is performed using binary\r\n * search, which is more efficient than a linear search for reasonably large arrays.\r\n *\r\n * The comparison function must meet the following criteria, given 'lhs' and 'rhs' of type T:\r\n * - If lhs is equal to rhs, returns 0\r\n * - If lhs is less than rhs, returns a negative value\r\n * - If lhs is greater than rhs, returns a positive value\r\n * - If compare(lhs, rhs) returns 0, then compare(rhs, lhs) must also return 0\r\n * - If compare(lhs, rhs) returns a negative value, then compare(rhs, lhs) must return a positive value, and vice versa.\r\n *\r\n * Note that the array is read-only only from the perspective of its public interface. Mutation methods are defined for internal use by sub-types.\r\n *\r\n * @see [[SortedArray]] for a general-purpose mutable sorted array.\r\n * @public\r\n */\r\nexport class ReadonlySortedArray<T> implements Iterable<T> {\r\n protected _array: T[] = [];\r\n protected readonly _compare: OrderedComparator<T>;\r\n protected readonly _clone: CloneFunction<T>;\r\n protected readonly _duplicatePolicy: DuplicatePolicy;\r\n\r\n /**\r\n * Construct a new ReadonlySortedArray<T>.\r\n * @param compare The function used to compare elements within the array.\r\n * @param duplicatePolicy Policy for handling attempts to insert a value when an equivalent value already exists. If the input is a boolean, then `true` indicates [[DuplicatePolicy.Allow]], and `false` indicates [[DuplicatePolicy.Retain]].\r\n * @param clone The function invoked to clone a new element for insertion into the array. The default implementation simply returns its input.\r\n */\r\n protected constructor(compare: OrderedComparator<T>, duplicatePolicy: DuplicatePolicy | boolean = false, clone: CloneFunction<T> = shallowClone) {\r\n this._compare = compare;\r\n this._clone = clone;\r\n if (typeof duplicatePolicy === \"boolean\")\r\n duplicatePolicy = duplicatePolicy ? DuplicatePolicy.Allow : DuplicatePolicy.Retain;\r\n\r\n this._duplicatePolicy = duplicatePolicy;\r\n }\r\n\r\n /** The number of elements in the array */\r\n public get length(): number { return this._array.length; }\r\n\r\n /** Returns true if the array contains no elements. */\r\n public get isEmpty(): boolean { return 0 === this.length; }\r\n\r\n /** Returns an iterator over the contents of the array in sorted order, suitable for use in `for-of` loops. */\r\n public [Symbol.iterator](): Iterator<T> { return this._array[Symbol.iterator](); }\r\n\r\n /**\r\n * Looks up the index of an element comparing equal to the specified value using binary search.\r\n * @param value The value to search for\r\n * @returns the index of the first equivalent element found in the array, or -1 if no such element exists.\r\n */\r\n public indexOf(value: T): number {\r\n const bound = this.lowerBound(value);\r\n return bound.equal ? bound.index : -1;\r\n }\r\n\r\n /**\r\n * Returns true if this array contains at least one value comparing equal to the specified value.\r\n * @param value The value to search for\r\n * @returns true if an equivalent element exists in the array.\r\n */\r\n public contains(value: T): boolean {\r\n return -1 !== this.indexOf(value);\r\n }\r\n\r\n /**\r\n * Looks up an element comparing equal to the specified value using binary search.\r\n * @param value The value to search for\r\n * @returns the first equivalent element found in the array, or undefined if no such element exists.\r\n */\r\n public findEqual(value: T): T | undefined {\r\n const index = this.indexOf(value);\r\n return -1 !== index ? this._array[index] : undefined;\r\n }\r\n\r\n /** Find an element that compares as equivalent based on some criterion. If multiple elements are equivalent, the specific one returned is unspecified.\r\n * As an example, consider a `SortedArray<ModelState>` which uses `ModelState.id` as its ordering criterion. To find a model by its Id,\r\n * use `sortedArray.findEquivalent((element) => compareStrings(element.id, modelId))` where `modelId` is an [[Id64String]].\r\n * @param criterion A function accepting an element and returning 0 if it compares as equivalent, a negative number if it compares as \"less-than\", or a positive value if it compares as \"greater-than\".\r\n * @returns The first element found that meets the criterion, or `undefined` if no elements meet the criterion.\r\n * @see [[indexOfEquivalent]].\r\n * @public\r\n */\r\n public findEquivalent(criterion: (element: T) => number): T | undefined {\r\n const index = this.indexOfEquivalent(criterion);\r\n return -1 !== index ? this._array[index] : undefined;\r\n }\r\n\r\n /** Find the index of an element that compares as equivalent based on some criterion. If multiple elements are equivalent, the specific one returned is unspecified.\r\n * As an example, consider a `SortedArray<ModelState>` which uses `ModelState.id` as its ordering criterion. To find the index of a model by its Id,\r\n * use `sortedArray.indexOfEquivalent((element) => compareStrings(element.id, modelId))` where `modelId` is an [[Id64String]].\r\n * @param criterion A function accepting an element and returning 0 if it compares as equivalent, a negative number if the element compares as \"less-than\", or a positive value if the element compares as \"greater-than\".\r\n * @returns The index of the first element found that meets the criterion, or -1 if no elements meet the criterion.\r\n * @public\r\n */\r\n public indexOfEquivalent(criterion: (element: T) => number): number {\r\n // NB: Must invert the ordering.\r\n const bound = lowerBoundOfEquivalent(this._array, (elem: T) => 0 - criterion(elem));\r\n return bound.equal ? bound.index : -1;\r\n }\r\n\r\n /**\r\n * Looks up an element by its index in the array.\r\n * @param index The array index\r\n * @returns the element corresponding to that position in the array, or undefined if the supplied index exceeds the length of the array.\r\n */\r\n public get(index: number): T | undefined { return index < this.length ? this._array[index] : undefined; }\r\n\r\n /** Apply a function to each element in the array, in sorted order.\r\n * @param func The function to be applied.\r\n */\r\n public forEach(func: (value: T) => void): void {\r\n for (let i = 0; i < this.length; i++)\r\n func(this._array[i]);\r\n }\r\n\r\n /**\r\n * Computes the position at which the specified value should be inserted to maintain sorted order.\r\n * @param value The value whose position is to be computed.\r\n * @returns an object with 'index' corresponding to the computed position and 'equal' set to true if an equivalent element already exists at that index.\r\n */\r\n protected lowerBound(value: T): { index: number, equal: boolean } { return lowerBound(value, this._array, this._compare); }\r\n\r\n /** Clears the contents of the sorted array. */\r\n protected _clear(): void { this._array.length = 0; }\r\n\r\n /** Extracts the sorted array as a T[] and empties the contents of this ReadonlySortedArray.\r\n * @returns the contents of this ReadonlySortedArray as a T[].\r\n */\r\n protected _extractArray(): T[] {\r\n const result = this._array;\r\n this._array = [];\r\n return result;\r\n }\r\n\r\n /**\r\n * Attempts to insert a new value into the array at a position determined by the ordering.\r\n * The behavior differs based on the array's [[DuplicatePolicy]]:\r\n * If duplicates are **not** permitted, then:\r\n * - If an equivalent element already exists in the array:\r\n * - [[DuplicatePolicy.Retain]]: nothing will be inserted and the index of the existing element will be returned.\r\n * - [[DuplicatePolicy.Replace]]: the input value will overwrite the existing element at the same index and that index will be returned.\r\n * - Otherwise, the element is inserted and its index is returned.\r\n * If duplicates **are** permitted, then:\r\n * - The element will be inserted in a correct position based on the sorting criterion;\r\n * - The position of the element relative to other elements comparing as equal to it is unspecified; and\r\n * - The actual index of the newly-inserted element is returned.\r\n * If the element is to be inserted, then the supplied value will be passed to the clone function supplied to the constructor and the result will be inserted into the array.\r\n * @param value The value to insert\r\n * @param onInsert The optional callback method to call if insertion occurs with the inserted value\r\n * @returns the index in the array of the newly-inserted value, or, if duplicates are not permitted and an equivalent value already exists, the index of the equivalent value.\r\n */\r\n protected _insert(value: T, onInsert?: (value: T) => any): number {\r\n const bound = this.lowerBound(value);\r\n\r\n if (bound.equal) {\r\n switch (this._duplicatePolicy) {\r\n case DuplicatePolicy.Retain:\r\n return bound.index;\r\n case DuplicatePolicy.Replace:\r\n this._array[bound.index] = this._clone(value);\r\n if (onInsert)\r\n onInsert(value);\r\n\r\n return bound.index;\r\n }\r\n }\r\n\r\n this._array.splice(bound.index, 0, this._clone(value));\r\n if (undefined !== onInsert)\r\n onInsert(value);\r\n\r\n return bound.index;\r\n }\r\n\r\n /**\r\n * Removes the first occurrence of a value comparing equal to the specified value from the array.\r\n * @param value The value of the element to delete\r\n * @returns the index of the deleted value, or -1 if no such element exists.\r\n */\r\n protected _remove(value: T): number {\r\n const bound = this.lowerBound(value);\r\n if (bound.equal) {\r\n this._array.splice(bound.index, 1);\r\n return bound.index;\r\n } else {\r\n return -1;\r\n }\r\n }\r\n}\r\n\r\n/**\r\n * Maintains an array of some type T in sorted order. The ordering is specified by a function supplied\r\n * by the user.\r\n * By default, only unique elements are permitted; attempting to insert a new element that compares\r\n * as equal to an element already in the array will not modify the contents of the array.\r\n *\r\n * This allows a SortedArray<T> to behave like a Set<T> where T is an object and equality is determined\r\n * by some criterion other than object identity.\r\n *\r\n * Because the array is always sorted, querying for the presence of an element is performed using binary\r\n * search, which is more efficient than a linear search for reasonably large arrays.\r\n *\r\n * The user can also specify how the SortedArray takes ownership of inserted values, e.g., by cloning them.\r\n *\r\n * The comparison function must meet the following criteria, given 'lhs' and 'rhs' of type T:\r\n * - If lhs is equal to rhs, returns 0\r\n * - If lhs is less than rhs, returns a negative value\r\n * - If lhs is greater than rhs, returns a positive value\r\n * - If compare(lhs, rhs) returns 0, then compare(rhs, lhs) must also return 0\r\n * - If compare(lhs, rhs) returns a negative value, then compare(rhs, lhs) must return a positive value, and vice versa.\r\n *\r\n * Modifying an element in a way that affects the comparison function will produce unpredictable results, the\r\n * most likely of which is that the array will cease to be sorted.\r\n * @public\r\n */\r\nexport class SortedArray<T> extends ReadonlySortedArray<T> {\r\n /**\r\n * Construct a new SortedArray<T>.\r\n * @param compare The function used to compare elements within the array.\r\n * @param duplicatePolicy Policy for handling attempts to insert a value when an equivalent value already exists. If the input is a boolean, then `true` indicates [[DuplicatePolicy.Allow]], and `false` indicates [[DuplicatePolicy.Retain]].\r\n * @param clone The function invoked to clone a new element for insertion into the array. The default implementation simply returns its input.\r\n */\r\n public constructor(compare: OrderedComparator<T>, duplicatePolicy: DuplicatePolicy | boolean = false, clone: CloneFunction<T> = shallowClone) {\r\n super(compare, duplicatePolicy, clone);\r\n }\r\n\r\n /** Clears the contents of the sorted array. */\r\n public clear(): void { this._clear(); }\r\n\r\n /** Extracts the sorted array as a T[] and empties the contents of this SortedArray.\r\n * @returns the contents of this SortedArray as a T[].\r\n */\r\n public extractArray(): T[] { return this._extractArray(); }\r\n\r\n /**\r\n * Attempts to insert a new value into the array at a position determined by the ordering.\r\n * The behavior differs based on whether or not duplicate elements are permitted.\r\n * If duplicates are **not** permitted, then:\r\n * - If an equivalent element already exists in the array, nothing will be inserted and the index of the existing element will be returned.\r\n * - Otherwise, the element is inserted and its index is returned.\r\n * If duplicates **are** permitted, then:\r\n * - The element will be inserted in a correct position based on the sorting criterion;\r\n * - The position of the element relative to other elements comparing as equal to it is unspecified; and\r\n * - The actual index of the newly-inserted element is returned.\r\n * If the element is to be inserted, then the supplied value will be passed to the clone function supplied to the constructor and the result will be inserted into the array.\r\n * @param value The value to insert\r\n * @param onInsert The optional callback method to call if insertion occurs with the inserted value\r\n * @returns the index in the array of the newly-inserted value, or, if duplicates are not permitted and an equivalent value already exists, the index of the equivalent value.\r\n */\r\n public insert(value: T, onInsert?: (value: T) => any): number { return this._insert(value, onInsert); }\r\n\r\n /**\r\n * Removes the first occurrence of a value comparing equal to the specified value from the array.\r\n * @param value The value of the element to delete\r\n * @returns the index of the deleted value, or -1 if no such element exists.\r\n */\r\n public remove(value: T): number { return this._remove(value); }\r\n}\r\n"]}
1
+ {"version":3,"file":"SortedArray.js","sourceRoot":"","sources":["../../src/SortedArray.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAWH;;;;;;GAMG;AACH,SAAgB,YAAY,CAAI,KAAQ;IACtC,OAAO,KAAK,CAAC;AACf,CAAC;AAFD,oCAEC;AAED;;;;;;;GAOG;AACH,SAAgB,UAAU,CAAW,KAAQ,EAAE,IAAS,EAAE,OAAgC;IACxF,OAAO,sBAAsB,CAAC,IAAI,EAAE,CAAC,OAAU,EAAE,EAAE,CAAC,OAAO,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC,CAAC;AAC/E,CAAC;AAFD,gCAEC;AAED,SAAS,sBAAsB,CAAI,IAAS,EAAE,SAAiC;IAC7E,IAAI,GAAG,GAAG,CAAC,CAAC;IACZ,IAAI,IAAI,GAAG,IAAI,CAAC,MAAM,CAAC;IACvB,OAAO,GAAG,GAAG,IAAI,EAAE;QACjB,MAAM,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,GAAG,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;QACzC,MAAM,IAAI,GAAG,SAAS,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;QAClC,IAAI,CAAC,KAAK,IAAI;YACZ,OAAO,EAAE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K,CAAC,KAAK,EAAE,CAAC,EAAE,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;QACvD,IAAI,SAAS,KAAK,QAAQ;YACxB,QAAQ,CAAC,KAAK,CAAC,CAAC;QAElB,OAAO,KAAK,CAAC,KAAK,CAAC;IACrB,CAAC;IAED;;;;OAIG;IACO,OAAO,CAAC,KAAQ;QACxB,MAAM,KAAK,GAAG,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;QACrC,IAAI,KAAK,CAAC,KAAK,EAAE;YACf,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;YACnC,OAAO,KAAK,CAAC,KAAK,CAAC;SACpB;aAAM;YACL,OAAO,CAAC,CAAC,CAAC;SACX;IACH,CAAC;CACF;AA7KD,kDA6KC;AAED;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,MAAa,WAAe,SAAQ,mBAAsB;IACxD;;;;;OAKG;IACH,YAAmB,OAA6B,EAAE,kBAA6C,KAAK,EAAE,QAA0B,YAAY;QAC1I,KAAK,CAAC,OAAO,EAAE,eAAe,EAAE,KAAK,CAAC,CAAC;IACzC,CAAC;IAED,+CAA+C;IACxC,KAAK,KAAW,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC;IAEvC;;OAEG;IACI,YAAY,KAAU,OAAO,IAAI,CAAC,aAAa,EAAE,CAAC,CAAC,CAAC;IAE3D;;;;;;;;;;;;;;OAcG;IACI,MAAM,CAAC,KAAQ,EAAE,QAA4B,IAAY,OAAO,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC;IAEvG;;;;OAIG;IACI,MAAM,CAAC,KAAQ,IAAY,OAAO,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;CAChE;AA1CD,kCA0CC","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n/** @packageDocumentation\r\n * @module Collections\r\n */\r\n\r\nimport { OrderedComparator } from \"./Compare\";\r\n\r\n/**\r\n * A function that, given a value of type T, returns a copy of that value. Such functions are used by various collection classes.\r\n * It is up to the function to decide how deeply or shallowly the value is cloned. For example, [[shallowClone]] simply returns the input.\r\n * @public\r\n */\r\nexport type CloneFunction<T> = (value: T) => T;\r\n\r\n/**\r\n * A [[CloneFunction]] that, given a value of type T, returns the same value.\r\n * Useful as a default argument for functions that can alternatively accept custom logic for cloning values of object type.\r\n * @param value The value to clone.\r\n * @returns the input value.\r\n * @public\r\n */\r\nexport function shallowClone<T>(value: T) {\r\n return value;\r\n}\r\n\r\n/**\r\n * Given a sorted array, computes the position at which the specified value should be inserted into the array so that the array remains sorted.\r\n * @param value The value whose position is to be computed.\r\n * @param list An array of U already sorted according to the comparison criterion.\r\n * @param compare The function used to compare the value with elements in `list`.\r\n * @returns an object with 'index' corresponding to the computed position and 'equal' set to true if an equivalent element already exists at that index.\r\n * @public\r\n */\r\nexport function lowerBound<T, U = T>(value: T, list: U[], compare: OrderedComparator<T, U>): { index: number, equal: boolean } {\r\n return lowerBoundOfEquivalent(list, (element: U) => compare(value, element));\r\n}\r\n\r\nfunction lowerBoundOfEquivalent<T>(list: T[], criterion: (element: T) => number): { index: number, equal: boolean } {\r\n let low = 0;\r\n let high = list.length;\r\n while (low < high) {\r\n const mid = Math.floor((low + high) / 2);\r\n const comp = criterion(list[mid]);\r\n if (0 === comp)\r\n return { index: mid, equal: true };\r\n else if (comp < 0)\r\n high = mid;\r\n else\r\n low = mid + 1;\r\n }\r\n\r\n return { index: low, equal: false };\r\n}\r\n\r\n/** Describes how duplicate values are handled when inserting into a [[SortedArray]].\r\n * A \"duplicate\" value is one that compares equal to a value already present in the array, per the array's comparison function.\r\n * @public\r\n */\r\nexport enum DuplicatePolicy {\r\n /** The array allows duplicate values to be inserted. All duplicate values will be adjacent in the array, but the ordering between duplicate values is unspecified.\r\n * @note In the presence of duplicate values, functions like [[SortedArray.indexOf]] and [[SortedArray.findEqual]] will return one of the values - exactly which one is unspecified.\r\n */\r\n Allow,\r\n /** Duplicate values are forbidden - when attempting to insert a value equivalent to one already present, the already-present value is retained. */\r\n Retain,\r\n /** Duplicate values are forbidden - when attempting to insert a value equivalent to one already present, the already-present value is replaced by the new value.\r\n * This can be useful when the value type carries additional data that is not evaluated by the comparison function.\r\n */\r\n Replace,\r\n}\r\n\r\n/**\r\n * A read-only view of an array of some type T sorted according to some user-supplied criterion.\r\n * Duplicate elements may be present, though sub-types may enforce uniqueness of elements.\r\n * In the absence of duplicates, a ReadonlySortedArray<T> can behave like a Set<T> where T is an object and equality is determined\r\n * by some criterion other than object identity.\r\n *\r\n * Because the array is always sorted, querying for the presence of an element is performed using binary\r\n * search, which is more efficient than a linear search for reasonably large arrays.\r\n *\r\n * The comparison function must meet the following criteria, given 'lhs' and 'rhs' of type T:\r\n * - If lhs is equal to rhs, returns 0\r\n * - If lhs is less than rhs, returns a negative value\r\n * - If lhs is greater than rhs, returns a positive value\r\n * - If compare(lhs, rhs) returns 0, then compare(rhs, lhs) must also return 0\r\n * - If compare(lhs, rhs) returns a negative value, then compare(rhs, lhs) must return a positive value, and vice versa.\r\n *\r\n * Note that the array is read-only only from the perspective of its public interface. Mutation methods are defined for internal use by sub-types.\r\n *\r\n * @see [[SortedArray]] for a general-purpose mutable sorted array.\r\n * @public\r\n */\r\nexport class ReadonlySortedArray<T> implements Iterable<T> {\r\n protected _array: T[] = [];\r\n protected readonly _compare: OrderedComparator<T>;\r\n protected readonly _clone: CloneFunction<T>;\r\n protected readonly _duplicatePolicy: DuplicatePolicy;\r\n\r\n /**\r\n * Construct a new ReadonlySortedArray<T>.\r\n * @param compare The function used to compare elements within the array.\r\n * @param duplicatePolicy Policy for handling attempts to insert a value when an equivalent value already exists. If the input is a boolean, then `true` indicates [[DuplicatePolicy.Allow]], and `false` indicates [[DuplicatePolicy.Retain]].\r\n * @param clone The function invoked to clone a new element for insertion into the array. The default implementation simply returns its input.\r\n */\r\n protected constructor(compare: OrderedComparator<T>, duplicatePolicy: DuplicatePolicy | boolean = false, clone: CloneFunction<T> = shallowClone) {\r\n this._compare = compare;\r\n this._clone = clone;\r\n if (typeof duplicatePolicy === \"boolean\")\r\n duplicatePolicy = duplicatePolicy ? DuplicatePolicy.Allow : DuplicatePolicy.Retain;\r\n\r\n this._duplicatePolicy = duplicatePolicy;\r\n }\r\n\r\n /** The number of elements in the array */\r\n public get length(): number { return this._array.length; }\r\n\r\n /** Returns true if the array contains no elements. */\r\n public get isEmpty(): boolean { return 0 === this.length; }\r\n\r\n /** Returns an iterator over the contents of the array in sorted order, suitable for use in `for-of` loops. */\r\n public [Symbol.iterator](): Iterator<T> { return this._array[Symbol.iterator](); }\r\n\r\n /**\r\n * Looks up the index of an element comparing equal to the specified value using binary search.\r\n * @param value The value to search for\r\n * @returns the index of the first equivalent element found in the array, or -1 if no such element exists.\r\n */\r\n public indexOf(value: T): number {\r\n const bound = this.lowerBound(value);\r\n return bound.equal ? bound.index : -1;\r\n }\r\n\r\n /**\r\n * Returns true if this array contains at least one value comparing equal to the specified value.\r\n * @param value The value to search for\r\n * @returns true if an equivalent element exists in the array.\r\n */\r\n public contains(value: T): boolean {\r\n return -1 !== this.indexOf(value);\r\n }\r\n\r\n /**\r\n * Looks up an element comparing equal to the specified value using binary search.\r\n * @param value The value to search for\r\n * @returns the first equivalent element found in the array, or undefined if no such element exists.\r\n */\r\n public findEqual(value: T): T | undefined {\r\n const index = this.indexOf(value);\r\n return -1 !== index ? this._array[index] : undefined;\r\n }\r\n\r\n /** Find an element that compares as equivalent based on some criterion. If multiple elements are equivalent, the specific one returned is unspecified.\r\n * As an example, consider a `SortedArray<ModelState>` which uses `ModelState.id` as its ordering criterion. To find a model by its Id,\r\n * use `sortedArray.findEquivalent((element) => compareStrings(element.id, modelId))` where `modelId` is an [[Id64String]].\r\n * @param criterion A function accepting an element and returning 0 if it compares as equivalent, a negative number if it compares as \"less-than\", or a positive value if it compares as \"greater-than\".\r\n * @returns The first element found that meets the criterion, or `undefined` if no elements meet the criterion.\r\n * @see [[indexOfEquivalent]].\r\n * @public\r\n */\r\n public findEquivalent(criterion: (element: T) => number): T | undefined {\r\n const index = this.indexOfEquivalent(criterion);\r\n return -1 !== index ? this._array[index] : undefined;\r\n }\r\n\r\n /** Find the index of an element that compares as equivalent based on some criterion. If multiple elements are equivalent, the specific one returned is unspecified.\r\n * As an example, consider a `SortedArray<ModelState>` which uses `ModelState.id` as its ordering criterion. To find the index of a model by its Id,\r\n * use `sortedArray.indexOfEquivalent((element) => compareStrings(element.id, modelId))` where `modelId` is an [[Id64String]].\r\n * @param criterion A function accepting an element and returning 0 if it compares as equivalent, a negative number if the element compares as \"less-than\", or a positive value if the element compares as \"greater-than\".\r\n * @returns The index of the first element found that meets the criterion, or -1 if no elements meet the criterion.\r\n * @public\r\n */\r\n public indexOfEquivalent(criterion: (element: T) => number): number {\r\n // NB: Must invert the ordering.\r\n const bound = lowerBoundOfEquivalent(this._array, (elem: T) => 0 - criterion(elem));\r\n return bound.equal ? bound.index : -1;\r\n }\r\n\r\n /**\r\n * Looks up an element by its index in the array.\r\n * @param index The array index\r\n * @returns the element corresponding to that position in the array, or undefined if the supplied index exceeds the length of the array.\r\n */\r\n public get(index: number): T | undefined { return index < this.length ? this._array[index] : undefined; }\r\n\r\n /** Apply a function to each element in the array, in sorted order.\r\n * @param func The function to be applied.\r\n */\r\n public forEach(func: (value: T) => void): void {\r\n for (let i = 0; i < this.length; i++)\r\n func(this._array[i]);\r\n }\r\n\r\n /**\r\n * Computes the position at which the specified value should be inserted to maintain sorted order.\r\n * @param value The value whose position is to be computed.\r\n * @returns an object with 'index' corresponding to the computed position and 'equal' set to true if an equivalent element already exists at that index.\r\n */\r\n protected lowerBound(value: T): { index: number, equal: boolean } { return lowerBound(value, this._array, this._compare); }\r\n\r\n /** Clears the contents of the sorted array. */\r\n protected _clear(): void { this._array.length = 0; }\r\n\r\n /** Extracts the sorted array as a T[] and empties the contents of this ReadonlySortedArray.\r\n * @returns the contents of this ReadonlySortedArray as a T[].\r\n */\r\n protected _extractArray(): T[] {\r\n const result = this._array;\r\n this._array = [];\r\n return result;\r\n }\r\n\r\n /**\r\n * Attempts to insert a new value into the array at a position determined by the ordering.\r\n * The behavior differs based on the array's [[DuplicatePolicy]]:\r\n * If duplicates are **not** permitted, then:\r\n * - If an equivalent element already exists in the array:\r\n * - [[DuplicatePolicy.Retain]]: nothing will be inserted and the index of the existing element will be returned.\r\n * - [[DuplicatePolicy.Replace]]: the input value will overwrite the existing element at the same index and that index will be returned.\r\n * - Otherwise, the element is inserted and its index is returned.\r\n * If duplicates **are** permitted, then:\r\n * - The element will be inserted in a correct position based on the sorting criterion;\r\n * - The position of the element relative to other elements comparing as equal to it is unspecified; and\r\n * - The actual index of the newly-inserted element is returned.\r\n * If the element is to be inserted, then the supplied value will be passed to the clone function supplied to the constructor and the result will be inserted into the array.\r\n * @param value The value to insert\r\n * @param onInsert The optional callback method to call if insertion occurs with the inserted value\r\n * @returns the index in the array of the newly-inserted value, or, if duplicates are not permitted and an equivalent value already exists, the index of the equivalent value.\r\n */\r\n protected _insert(value: T, onInsert?: (value: T) => any): number {\r\n const bound = this.lowerBound(value);\r\n\r\n if (bound.equal) {\r\n switch (this._duplicatePolicy) {\r\n case DuplicatePolicy.Retain:\r\n return bound.index;\r\n case DuplicatePolicy.Replace:\r\n this._array[bound.index] = this._clone(value);\r\n if (onInsert)\r\n onInsert(value);\r\n\r\n return bound.index;\r\n }\r\n }\r\n\r\n this._array.splice(bound.index, 0, this._clone(value));\r\n if (undefined !== onInsert)\r\n onInsert(value);\r\n\r\n return bound.index;\r\n }\r\n\r\n /**\r\n * Removes the first occurrence of a value comparing equal to the specified value from the array.\r\n * @param value The value of the element to delete\r\n * @returns the index of the deleted value, or -1 if no such element exists.\r\n */\r\n protected _remove(value: T): number {\r\n const bound = this.lowerBound(value);\r\n if (bound.equal) {\r\n this._array.splice(bound.index, 1);\r\n return bound.index;\r\n } else {\r\n return -1;\r\n }\r\n }\r\n}\r\n\r\n/**\r\n * Maintains an array of some type T in sorted order. The ordering is specified by a function supplied\r\n * by the user.\r\n * By default, only unique elements are permitted; attempting to insert a new element that compares\r\n * as equal to an element already in the array will not modify the contents of the array.\r\n *\r\n * This allows a SortedArray<T> to behave like a Set<T> where T is an object and equality is determined\r\n * by some criterion other than object identity.\r\n *\r\n * Because the array is always sorted, querying for the presence of an element is performed using binary\r\n * search, which is more efficient than a linear search for reasonably large arrays.\r\n *\r\n * The user can also specify how the SortedArray takes ownership of inserted values, e.g., by cloning them.\r\n *\r\n * The comparison function must meet the following criteria, given 'lhs' and 'rhs' of type T:\r\n * - If lhs is equal to rhs, returns 0\r\n * - If lhs is less than rhs, returns a negative value\r\n * - If lhs is greater than rhs, returns a positive value\r\n * - If compare(lhs, rhs) returns 0, then compare(rhs, lhs) must also return 0\r\n * - If compare(lhs, rhs) returns a negative value, then compare(rhs, lhs) must return a positive value, and vice versa.\r\n *\r\n * Modifying an element in a way that affects the comparison function will produce unpredictable results, the\r\n * most likely of which is that the array will cease to be sorted.\r\n * @public\r\n */\r\nexport class SortedArray<T> extends ReadonlySortedArray<T> {\r\n /**\r\n * Construct a new SortedArray<T>.\r\n * @param compare The function used to compare elements within the array.\r\n * @param duplicatePolicy Policy for handling attempts to insert a value when an equivalent value already exists. If the input is a boolean, then `true` indicates [[DuplicatePolicy.Allow]], and `false` indicates [[DuplicatePolicy.Retain]].\r\n * @param clone The function invoked to clone a new element for insertion into the array. The default implementation simply returns its input.\r\n */\r\n public constructor(compare: OrderedComparator<T>, duplicatePolicy: DuplicatePolicy | boolean = false, clone: CloneFunction<T> = shallowClone) {\r\n super(compare, duplicatePolicy, clone);\r\n }\r\n\r\n /** Clears the contents of the sorted array. */\r\n public clear(): void { this._clear(); }\r\n\r\n /** Extracts the sorted array as a T[] and empties the contents of this SortedArray.\r\n * @returns the contents of this SortedArray as a T[].\r\n */\r\n public extractArray(): T[] { return this._extractArray(); }\r\n\r\n /**\r\n * Attempts to insert a new value into the array at a position determined by the ordering.\r\n * The behavior differs based on whether or not duplicate elements are permitted.\r\n * If duplicates are **not** permitted, then:\r\n * - If an equivalent element already exists in the array, nothing will be inserted and the index of the existing element will be returned.\r\n * - Otherwise, the element is inserted and its index is returned.\r\n * If duplicates **are** permitted, then:\r\n * - The element will be inserted in a correct position based on the sorting criterion;\r\n * - The position of the element relative to other elements comparing as equal to it is unspecified; and\r\n * - The actual index of the newly-inserted element is returned.\r\n * If the element is to be inserted, then the supplied value will be passed to the clone function supplied to the constructor and the result will be inserted into the array.\r\n * @param value The value to insert\r\n * @param onInsert The optional callback method to call if insertion occurs with the inserted value\r\n * @returns the index in the array of the newly-inserted value, or, if duplicates are not permitted and an equivalent value already exists, the index of the equivalent value.\r\n */\r\n public insert(value: T, onInsert?: (value: T) => any): number { return this._insert(value, onInsert); }\r\n\r\n /**\r\n * Removes the first occurrence of a value comparing equal to the specified value from the array.\r\n * @param value The value of the element to delete\r\n * @returns the index of the deleted value, or -1 if no such element exists.\r\n */\r\n public remove(value: T): number { return this._remove(value); }\r\n}\r\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"StringUtils.d.ts","sourceRoot":"","sources":["../../src/StringUtils.ts"],"names":[],"mappings":"AAIA;;GAEG;AA+GH;;GAEG;AACH,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,UAAU,GAAG,MAAM,GAAG,SAAS,CAEzE;AAKD;;;;;;GAMG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,UAAU,GAAG,MAAM,GAAG,SAAS,CAcjE;AAED;;;;;GAKG;AACH,wBAAgB,wBAAwB,CAAC,MAAM,EAAE,MAAM,GAAG,UAAU,CAEnE"}
1
+ {"version":3,"file":"StringUtils.d.ts","sourceRoot":"","sources":["../../src/StringUtils.ts"],"names":[],"mappings":"AAIA;;GAEG;AAiHH;;GAEG;AACH,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,UAAU,GAAG,MAAM,GAAG,SAAS,CAEzE;AAKD;;;;;;GAMG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,UAAU,GAAG,MAAM,GAAG,SAAS,CAcjE;AAED;;;;;GAKG;AACH,wBAAgB,wBAAwB,CAAC,MAAM,EAAE,MAAM,GAAG,UAAU,CAEnE"}
@@ -14,7 +14,9 @@ exports.base64StringToUint8Array = exports.utf8ToString = exports.utf8ToStringPo
14
14
  /** @internal */
15
15
  var Utf8ToString;
16
16
  (function (Utf8ToString) {
17
- function inRange(a, min, max) { return min <= a && a <= max; }
17
+ function inRange(a, min, max) {
18
+ return min <= a && a <= max;
19
+ }
18
20
  function utf8Handler(bytes) {
19
21
  let codePoint = 0;
20
22
  let bytesSeen = 0;
@@ -1 +1 @@
1
- {"version":3,"file":"StringUtils.js","sourceRoot":"","sources":["../../src/StringUtils.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,oFAAoF;AACpF,0GAA0G;AAC1G,8EAA8E;AAC9E,gBAAgB;AAChB,IAAU,YAAY,CAuGrB;AAvGD,WAAU,YAAY;IACpB,SAAS,OAAO,CAAC,CAAS,EAAE,GAAW,EAAE,GAAW,IAAa,OAAO,GAAG,IAAI,CAAC,IAAI,CAAC,IAAI,GAAG,CAAC,CAAC,CAAC;IAE/F,SAAS,WAAW,CAAC,KAAiB;QACpC,IAAI,SAAS,GAAG,CAAC,CAAC;QAClB,IAAI,SAAS,GAAG,CAAC,CAAC;QAClB,IAAI,WAAW,GAAG,CAAC,CAAC;QACpB,IAAI,aAAa,GAAG,IAAI,CAAC;QACzB,IAAI,aAAa,GAAG,IAAI,CAAC;QAEzB,MAAM,UAAU,GAAa,EAAE,CAAC;QAChC,MAAM,MAAM,GAAG,KAAK,CAAC,MAAM,CAAC;QAC5B,KAAK,IAAI,CAAC,GAAG,CAAC,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AgB,oBAAoB,CAAC,IAAgB;IACnD,OAAO,YAAY,CAAC,sBAAsB,CAAC,IAAI,CAAC,CAAC;AACnD,CAAC;AAFD,oDAEC;AAED,sDAAsD;AACtD,IAAI,oBAAoB,GAAG,IAAI,CAAC;AAEhC;;;;;;GAMG;AACH,SAAgB,YAAY,CAAC,IAAgB;IAC3C,IAAI,OAAgC,CAAC;IACrC,IAAI,oBAAoB,EAAE;QACxB,IAAI;YACF,OAAO,GAAG,IAAI,WAAW,CAAC,OAAO,CAAC,CAAC;SACpC;QAAC,OAAO,GAAG,EAAE;YACZ,oBAAoB,GAAG,KAAK,CAAC;SAC9B;KACF;IAED,IAAI,SAAS,KAAK,OAAO;QACvB,OAAO,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;;QAE5B,OAAO,oBAAoB,CAAC,IAAI,CAAC,CAAC;AACtC,CAAC;AAdD,oCAcC;AAED;;;;;GAKG;AACH,SAAgB,wBAAwB,CAAC,MAAc;IACrD,OAAO,IAAI,UAAU,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,8CAA8C;AAC3H,CAAC;AAFD,4DAEC","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n/** @packageDocumentation\r\n * @module Utils\r\n */\r\n\r\n// TextDecoder is not supported on all platforms - this is an alternative for utf-8.\r\n// From https://github.com/AnalyticalGraphicsInc/cesium/blob/master/Source/Core/getStringFromTypedArray.js\r\n// which is itself inspired by https://github.com/inexorabletash/text-encoding\r\n/** @internal */\r\nnamespace Utf8ToString {\r\n function inRange(a: number, min: number, max: number): boolean { return min <= a && a <= max; }\r\n\r\n function utf8Handler(bytes: Uint8Array): number[] | undefined {\r\n let codePoint = 0;\r\n let bytesSeen = 0;\r\n let bytesNeeded = 0;\r\n let lowerBoundary = 0x80;\r\n let upperBoundary = 0xbf;\r\n\r\n const codePoints: number[] = [];\r\n const length = bytes.length;\r\n for (let i = 0; i < length; i++) {\r\n const currentByte = bytes[i];\r\n\r\n // If bytesNeeded = 0, then we are starting a new character\r\n if (0 === bytesNeeded) {\r\n // 1 byte ascii character\r\n if (inRange(currentByte, 0x00, 0x7f)) {\r\n // return a code point whose value is byte.\r\n codePoints.push(currentByte);\r\n continue;\r\n }\r\n\r\n // 2 byte character\r\n if (inRange(currentByte, 0xc2, 0xdf)) {\r\n bytesNeeded = 1;\r\n codePoint = currentByte & 0x1f;\r\n continue;\r\n }\r\n\r\n // 3 byte character\r\n if (inRange(currentByte, 0xe0, 0xef)) {\r\n if (0xe0 === currentByte)\r\n lowerBoundary = 0xa0;\r\n else if (0xed === currentByte)\r\n upperBoundary = 0x9f;\r\n\r\n bytesNeeded = 2;\r\n codePoint = currentByte & 0xf;\r\n continue;\r\n }\r\n\r\n // 4 byte character\r\n if (inRange(currentByte, 0xf0, 0xf4)) {\r\n if (0xf0 === currentByte)\r\n lowerBoundary = 0x90;\r\n else if (0xf4 === currentByte)\r\n upperBoundary = 0x8f;\r\n\r\n bytesNeeded = 3;\r\n codePoint = currentByte & 0x7;\r\n continue;\r\n }\r\n\r\n // invalid utf-8\r\n return undefined;\r\n }\r\n\r\n // out of range so ignore the first part(s) of the character and continue with this byte on its own\r\n if (!inRange(currentByte, lowerBoundary, upperBoundary)) {\r\n codePoint = bytesNeeded = bytesSeen = 0;\r\n lowerBoundary = 0x80;\r\n upperBoundary = 0xbf;\r\n --i;\r\n continue;\r\n }\r\n\r\n // set appropriate boundaries since we've now checked byte 2 of a potential longer character\r\n lowerBoundary = 0x80;\r\n upperBoundary = 0xbf;\r\n\r\n // add byte to code point\r\n codePoint = (codePoint << 6) | (currentByte & 0x3f);\r\n\r\n // We have the correct number of bytes, so push and reset for next character\r\n ++bytesSeen;\r\n if (bytesSeen === bytesNeeded) {\r\n codePoints.push(codePoint);\r\n codePoint = bytesNeeded = bytesSeen = 0;\r\n }\r\n }\r\n\r\n return codePoints;\r\n }\r\n\r\n export function decodeWithFromCharCode(view: Uint8Array): string | undefined {\r\n let result = \"\";\r\n const codePoints = utf8Handler(view);\r\n if (undefined === codePoints)\r\n return undefined;\r\n\r\n for (let cp of codePoints) {\r\n if (cp <= 0xffff) {\r\n result += String.fromCharCode(cp);\r\n } else {\r\n cp -= 0x10000;\r\n result += String.fromCharCode((cp >> 10) + 0xd800, (cp & 0x3ff) + 0xdc00);\r\n }\r\n }\r\n\r\n return result;\r\n }\r\n}\r\n\r\n/** Exposed only for testing the fall-back used when TextDecoder is unsupported.\r\n * @internal\r\n */\r\nexport function utf8ToStringPolyfill(utf8: Uint8Array): string | undefined {\r\n return Utf8ToString.decodeWithFromCharCode(utf8);\r\n}\r\n\r\n// TextDecoder unsupported in Edge at time of writing.\r\nlet textDecoderSupported = true;\r\n\r\n/** Given an array of bytes containing a utf-8 string, convert to a string.\r\n * @param utf8: An array of utf-8 characters as a byte array\r\n * @returns An equivalent string, or undefined if the array does not contain a valid utf-8 string.\r\n * @note This function uses Javascript's TextDecoder if supported by the browser; otherwise, it\r\n * falls back to a less efficient polyfill.\r\n * @public\r\n */\r\nexport function utf8ToString(utf8: Uint8Array): string | undefined {\r\n let decoder: TextDecoder | undefined;\r\n if (textDecoderSupported) {\r\n try {\r\n decoder = new TextDecoder(\"utf-8\");\r\n } catch (_ex) {\r\n textDecoderSupported = false;\r\n }\r\n }\r\n\r\n if (undefined !== decoder)\r\n return decoder.decode(utf8);\r\n else\r\n return utf8ToStringPolyfill(utf8);\r\n}\r\n\r\n/** Given a base-64-encoded string, decode it into an array of bytes.\r\n * @param base64 The base-64-encoded string.\r\n * @returns the decoded byte array.\r\n * @throws DOMException if the length of the input string is not a multiple of 4.\r\n * @public\r\n */\r\nexport function base64StringToUint8Array(base64: string): Uint8Array {\r\n return new Uint8Array(atob(base64).split(\"\").map((c) => c.charCodeAt(0))); // eslint-disable-line deprecation/deprecation\r\n}\r\n"]}
1
+ {"version":3,"file":"StringUtils.js","sourceRoot":"","sources":["../../src/StringUtils.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,oFAAoF;AACpF,0GAA0G;AAC1G,8EAA8E;AAC9E,gBAAgB;AAChB,IAAU,YAAY,CAyGrB;AAzGD,WAAU,YAAY;IACpB,SAAS,OAAO,CAAC,CAAS,EAAE,GAAW,EAAE,GAAW;QAClD,OAAO,GAAG,IAAI,CAAC,IAAI,CAAC,IAAI,GAAG,CAAC;IAC9B,CAAC;IAED,SAAS,WAAW,CAAC,KAAiB;QACpC,IAAI,SAAS,GAAG,CAAC,CAAC;QAClB,IAAI,SAAS,GAAG,CAAC,CAAC;QAClB,IAAI,WAAW,GAAG,CAAC,CAAC;QACpB,IAAI,aAAa,GAAG,IAAI,CAAC;QACzB,IAAI,aAAa,GAAG,IAAI,CAAC;QAEzB,MAAM,UAAU,GAAa,EAAE,CAAC;QAChC,MAAM,MAAM,GAAG,KAAK,CAAC,MAAM,CAAC;QAC5B,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,MAAM,EAAE,CAAC,EAAE,EAAE;YAC/B,MAAM,WAAW,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC;YAE7B,2DAA2D;YAC3D,IAAI,CAAC,KAAK,WAAW,EAAE;gBACrB,yBAAyB;gBACzB,IAAI,OAAO,CAAC,WAAW,EAAE,IAAI,EAAE,IAAI,CAAC,EAAE;oBACpC,2CAA2C;oBAC3C,UAAU,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;oBAC7B,SAAS;iBACV;gBAED,mBAAmB;gBACnB,IAAI,OAAO,CAAC,WAAW,EAAE,IAAI,EAAE,IAAI,CAAC,EAAE;oBACpC,WAAW,GAAG,CAAC,CAAC;oBA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,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;;QAE5B,OAAO,oBAAoB,CAAC,IAAI,CAAC,CAAC;AACtC,CAAC;AAdD,oCAcC;AAED;;;;;GAKG;AACH,SAAgB,wBAAwB,CAAC,MAAc;IACrD,OAAO,IAAI,UAAU,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,8CAA8C;AAC3H,CAAC;AAFD,4DAEC","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n/** @packageDocumentation\r\n * @module Utils\r\n */\r\n\r\n// TextDecoder is not supported on all platforms - this is an alternative for utf-8.\r\n// From https://github.com/AnalyticalGraphicsInc/cesium/blob/master/Source/Core/getStringFromTypedArray.js\r\n// which is itself inspired by https://github.com/inexorabletash/text-encoding\r\n/** @internal */\r\nnamespace Utf8ToString {\r\n function inRange(a: number, min: number, max: number): boolean {\r\n return min <= a && a <= max;\r\n }\r\n\r\n function utf8Handler(bytes: Uint8Array): number[] | undefined {\r\n let codePoint = 0;\r\n let bytesSeen = 0;\r\n let bytesNeeded = 0;\r\n let lowerBoundary = 0x80;\r\n let upperBoundary = 0xbf;\r\n\r\n const codePoints: number[] = [];\r\n const length = bytes.length;\r\n for (let i = 0; i < length; i++) {\r\n const currentByte = bytes[i];\r\n\r\n // If bytesNeeded = 0, then we are starting a new character\r\n if (0 === bytesNeeded) {\r\n // 1 byte ascii character\r\n if (inRange(currentByte, 0x00, 0x7f)) {\r\n // return a code point whose value is byte.\r\n codePoints.push(currentByte);\r\n continue;\r\n }\r\n\r\n // 2 byte character\r\n if (inRange(currentByte, 0xc2, 0xdf)) {\r\n bytesNeeded = 1;\r\n codePoint = currentByte & 0x1f;\r\n continue;\r\n }\r\n\r\n // 3 byte character\r\n if (inRange(currentByte, 0xe0, 0xef)) {\r\n if (0xe0 === currentByte)\r\n lowerBoundary = 0xa0;\r\n else if (0xed === currentByte)\r\n upperBoundary = 0x9f;\r\n\r\n bytesNeeded = 2;\r\n codePoint = currentByte & 0xf;\r\n continue;\r\n }\r\n\r\n // 4 byte character\r\n if (inRange(currentByte, 0xf0, 0xf4)) {\r\n if (0xf0 === currentByte)\r\n lowerBoundary = 0x90;\r\n else if (0xf4 === currentByte)\r\n upperBoundary = 0x8f;\r\n\r\n bytesNeeded = 3;\r\n codePoint = currentByte & 0x7;\r\n continue;\r\n }\r\n\r\n // invalid utf-8\r\n return undefined;\r\n }\r\n\r\n // out of range so ignore the first part(s) of the character and continue with this byte on its own\r\n if (!inRange(currentByte, lowerBoundary, upperBoundary)) {\r\n codePoint = bytesNeeded = bytesSeen = 0;\r\n lowerBoundary = 0x80;\r\n upperBoundary = 0xbf;\r\n --i;\r\n continue;\r\n }\r\n\r\n // set appropriate boundaries since we've now checked byte 2 of a potential longer character\r\n lowerBoundary = 0x80;\r\n upperBoundary = 0xbf;\r\n\r\n // add byte to code point\r\n codePoint = (codePoint << 6) | (currentByte & 0x3f);\r\n\r\n // We have the correct number of bytes, so push and reset for next character\r\n ++bytesSeen;\r\n if (bytesSeen === bytesNeeded) {\r\n codePoints.push(codePoint);\r\n codePoint = bytesNeeded = bytesSeen = 0;\r\n }\r\n }\r\n\r\n return codePoints;\r\n }\r\n\r\n export function decodeWithFromCharCode(view: Uint8Array): string | undefined {\r\n let result = \"\";\r\n const codePoints = utf8Handler(view);\r\n if (undefined === codePoints)\r\n return undefined;\r\n\r\n for (let cp of codePoints) {\r\n if (cp <= 0xffff) {\r\n result += String.fromCharCode(cp);\r\n } else {\r\n cp -= 0x10000;\r\n result += String.fromCharCode((cp >> 10) + 0xd800, (cp & 0x3ff) + 0xdc00);\r\n }\r\n }\r\n\r\n return result;\r\n }\r\n}\r\n\r\n/** Exposed only for testing the fall-back used when TextDecoder is unsupported.\r\n * @internal\r\n */\r\nexport function utf8ToStringPolyfill(utf8: Uint8Array): string | undefined {\r\n return Utf8ToString.decodeWithFromCharCode(utf8);\r\n}\r\n\r\n// TextDecoder unsupported in Edge at time of writing.\r\nlet textDecoderSupported = true;\r\n\r\n/** Given an array of bytes containing a utf-8 string, convert to a string.\r\n * @param utf8: An array of utf-8 characters as a byte array\r\n * @returns An equivalent string, or undefined if the array does not contain a valid utf-8 string.\r\n * @note This function uses Javascript's TextDecoder if supported by the browser; otherwise, it\r\n * falls back to a less efficient polyfill.\r\n * @public\r\n */\r\nexport function utf8ToString(utf8: Uint8Array): string | undefined {\r\n let decoder: TextDecoder | undefined;\r\n if (textDecoderSupported) {\r\n try {\r\n decoder = new TextDecoder(\"utf-8\");\r\n } catch (_ex) {\r\n textDecoderSupported = false;\r\n }\r\n }\r\n\r\n if (undefined !== decoder)\r\n return decoder.decode(utf8);\r\n else\r\n return utf8ToStringPolyfill(utf8);\r\n}\r\n\r\n/** Given a base-64-encoded string, decode it into an array of bytes.\r\n * @param base64 The base-64-encoded string.\r\n * @returns the decoded byte array.\r\n * @throws DOMException if the length of the input string is not a multiple of 4.\r\n * @public\r\n */\r\nexport function base64StringToUint8Array(base64: string): Uint8Array {\r\n return new Uint8Array(atob(base64).split(\"\").map((c) => c.charCodeAt(0))); // eslint-disable-line deprecation/deprecation\r\n}\r\n"]}
package/lib/cjs/Time.d.ts CHANGED
@@ -104,7 +104,7 @@ export declare class StopWatch {
104
104
  get current(): BeDuration;
105
105
  /** Get the elapsed time, in seconds, since start() on a running timer. */
106
106
  get currentSeconds(): number;
107
- /** Get the elapsed time between start() and stop() on this timer. */
107
+ /** Get the elapsed time between start() and stop() on this timer in milliseconds. */
108
108
  get elapsed(): BeDuration;
109
109
  /** Get the elapsed time, in seconds, between start() and stop() on this timer. */
110
110
  get elapsedSeconds(): number;
@@ -1 +1 @@
1
-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AEG;IACI,MAAM,CAAC,KAAK,EAAE,WAAW,GAAG,OAAO;IAE1C;;OAEG;IACI,KAAK,CAAC,KAAK,EAAE,WAAW,GAAG,OAAO;IAEzC;;OAEG;IACI,KAAK,CAAC,QAAQ,EAAE,UAAU,GAAG,WAAW;IAE/C;;OAEG;IACI,IAAI,CAAC,QAAQ,EAAE,UAAU;CACjC;AAED;;GAEG;AACH,qBAAa,SAAS;IAeD,WAAW,CAAC;IAd/B,OAAO,CAAC,MAAM,CAAC,CAAc;IAC7B,OAAO,CAAC,KAAK,CAAC,CAAc;IAC5B,6DAA6D;IAC7D,IAAW,OAAO,IAAI,UAAU,CAAyH;IACzJ,0EAA0E;IAC1E,IAAW,cAAc,IAAI,MAAM,CAAiC;IACpE,qFAAqF;IACrF,IAAW,OAAO,IAAI,UAAU,CAAoK;IACpM,mFAAmF;IACnF,IAAW,cAAc,IAAI,MAAM,CAAiC;IACpE;;;OAGG;gBACgB,WAAW,CAAC,oBAAQ,EAAE,gBAAgB,UAAQ;IAKjE,yFAAyF;IAClF,KAAK,IAAI,IAAI;IAKpB,mEAAmE;IAC5D,IAAI,IAAI,UAAU;IAKzB,0BAA0B;IACnB,KAAK,IAAI,IAAI;CACrB"}
package/lib/cjs/Time.js CHANGED
@@ -132,14 +132,20 @@ class StopWatch {
132
132
  get current() { return BeDuration.fromMilliseconds(BeTimePoint.now().milliseconds - (!!this._start ? this._start.milliseconds : 0)); }
133
133
  /** Get the elapsed time, in seconds, since start() on a running timer. */
134
134
  get currentSeconds() { return this.current.seconds; }
135
- /** Get the elapsed time between start() and stop() on this timer. */
135
+ /** Get the elapsed time between start() and stop() on this timer in milliseconds. */
136
136
  get elapsed() { return BeDuration.fromMilliseconds((!!this._stop ? this._stop.milliseconds : BeTimePoint.now().milliseconds) - (!!this._start ? this._start.milliseconds : 0)); }
137
137
  /** Get the elapsed time, in seconds, between start() and stop() on this timer. */
138
138
  get elapsedSeconds() { return this.elapsed.seconds; }
139
139
  /** Start the stopwatch. Any future time measurements will be based on this new value. */
140
- start() { this.reset(); this._start = BeTimePoint.now(); }
140
+ start() {
141
+ this.reset();
142
+ this._start = BeTimePoint.now();
143
+ }
141
144
  /** Stop the stopwatch so that the duration can be viewed later. */
142
- stop() { this._stop = BeTimePoint.now(); return this.elapsed; }
145
+ stop() {
146
+ this._stop = BeTimePoint.now();
147
+ return this.elapsed;
148
+ }
143
149
  /** Clear the StopWatch */
144
150
  reset() { this._start = this._stop = undefined; }
145
151
  }