@bitblit/ratchet-common 4.0.99-alpha → 4.0.103-alpha

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 (298) hide show
  1. package/{dist/types → lib}/2d/line-2d.d.ts +1 -1
  2. package/{dist/types → lib}/2d/poly-line-2d.d.ts +1 -1
  3. package/{dist/types → lib}/2d/ratchet-2d.d.ts +4 -4
  4. package/{dist/es → lib}/2d/ratchet-2d.js +1 -1
  5. package/lib/2d/ratchet-2d.spec.js +117 -0
  6. package/{dist/types → lib}/build/ratchet-common-info.d.ts +1 -1
  7. package/{dist/types → lib}/histogram/histogram.d.ts +1 -4
  8. package/{dist/es → lib}/histogram/histogram.js +1 -3
  9. package/lib/histogram/histogram.spec.js +19 -0
  10. package/lib/jwt/common-jwt-token.d.ts +6 -0
  11. package/{dist/types → lib}/jwt/jwt-ratchet-like.d.ts +3 -6
  12. package/{dist/types → lib}/jwt/jwt-ratchet.d.ts +4 -13
  13. package/{dist/es → lib}/jwt/jwt-ratchet.js +12 -7
  14. package/lib/jwt/jwt-ratchet.spec.js +49 -0
  15. package/{dist/types → lib}/jwt/jwt-token-base.d.ts +0 -4
  16. package/lib/lang/array-ratchet.d.ts +14 -0
  17. package/{dist/es → lib}/lang/array-ratchet.js +2 -2
  18. package/lib/lang/array-ratchet.spec.js +68 -0
  19. package/{dist/types → lib}/lang/base64-ratchet.d.ts +1 -1
  20. package/{dist/es → lib}/lang/base64-ratchet.js +1 -1
  21. package/lib/lang/base64-ratchet.spec.js +28 -0
  22. package/{dist/es → lib}/lang/boolean-ratchet.js +1 -1
  23. package/lib/lang/boolean-ratchet.spec.js +81 -0
  24. package/{dist/types → lib}/lang/composite-last-success-provider.d.ts +1 -2
  25. package/{dist/es → lib}/lang/composite-last-success-provider.js +2 -0
  26. package/lib/lang/composite-last-success-provider.spec.js +26 -0
  27. package/{dist/es → lib}/lang/date-ratchet.js +5 -5
  28. package/lib/lang/date-ratchet.spec.js +21 -0
  29. package/{dist/es → lib}/lang/duration-ratchet.js +1 -1
  30. package/lib/lang/duration-ratchet.spec.js +39 -0
  31. package/lib/lang/enum-ratchet.d.ts +5 -0
  32. package/{dist/es → lib}/lang/enum-ratchet.js +1 -1
  33. package/lib/lang/enum-ratchet.spec.d.ts +5 -0
  34. package/lib/lang/enum-ratchet.spec.js +31 -0
  35. package/{dist/es → lib}/lang/error-ratchet.js +1 -1
  36. package/lib/lang/error-ratchet.spec.js +20 -0
  37. package/lib/lang/esm-ratchet.d.ts +4 -0
  38. package/lib/lang/esm-ratchet.js +11 -0
  39. package/{dist/types → lib}/lang/expiring-object.d.ts +1 -1
  40. package/{dist/es → lib}/lang/expiring-object.js +13 -4
  41. package/lib/lang/expiring-object.spec.js +51 -0
  42. package/{dist/es → lib}/lang/geolocation-ratchet.js +4 -4
  43. package/lib/lang/geolocation-ratchet.spec.d.ts +1 -0
  44. package/lib/lang/geolocation-ratchet.spec.js +74 -0
  45. package/{dist/es → lib}/lang/global-ratchet.js +3 -3
  46. package/lib/lang/global-ratchet.spec.d.ts +1 -0
  47. package/lib/lang/global-ratchet.spec.js +14 -0
  48. package/{dist/es → lib}/lang/key-value.js +2 -0
  49. package/lib/lang/last-success-provider.d.ts +3 -0
  50. package/lib/lang/last-success-provider.js +1 -0
  51. package/{dist/types → lib}/lang/map-ratchet.d.ts +1 -1
  52. package/{dist/es → lib}/lang/map-ratchet.js +3 -3
  53. package/lib/lang/map-ratchet.spec.d.ts +1 -0
  54. package/lib/lang/map-ratchet.spec.js +90 -0
  55. package/lib/lang/no.spec.d.ts +1 -0
  56. package/lib/lang/no.spec.js +7 -0
  57. package/{dist/es → lib}/lang/number-ratchet.js +3 -3
  58. package/lib/lang/number-ratchet.spec.d.ts +1 -0
  59. package/lib/lang/number-ratchet.spec.js +118 -0
  60. package/lib/lang/parsed-url.js +1 -0
  61. package/lib/lang/promise-ratchet.d.ts +18 -0
  62. package/{dist/es → lib}/lang/promise-ratchet.js +5 -5
  63. package/lib/lang/promise-ratchet.spec.d.ts +1 -0
  64. package/lib/lang/promise-ratchet.spec.js +74 -0
  65. package/{dist/es → lib}/lang/require-ratchet.js +1 -1
  66. package/lib/lang/require-ratchet.spec.d.ts +3 -0
  67. package/lib/lang/require-ratchet.spec.js +80 -0
  68. package/{dist/types → lib}/lang/stop-watch.d.ts +1 -1
  69. package/{dist/es → lib}/lang/stop-watch.js +9 -8
  70. package/{dist/es → lib}/lang/string-ratchet.js +2 -2
  71. package/lib/lang/string-ratchet.spec.d.ts +1 -0
  72. package/lib/lang/string-ratchet.spec.js +158 -0
  73. package/lib/lang/time-zone-ratchet.d.ts +19 -0
  74. package/{dist/es → lib}/lang/time-zone-ratchet.js +2 -1
  75. package/lib/lang/time-zone-ratchet.spec.d.ts +1 -0
  76. package/lib/lang/time-zone-ratchet.spec.js +40 -0
  77. package/{dist/types → lib}/lang/timeout-token.d.ts +1 -1
  78. package/{dist/es → lib}/lang/timeout-token.js +5 -3
  79. package/lib/lang/timeout-token.spec.d.ts +1 -0
  80. package/lib/lang/timeout-token.spec.js +9 -0
  81. package/{dist/types → lib}/lang/transform-ratchet.d.ts +1 -1
  82. package/{dist/es → lib}/lang/transform-ratchet.js +1 -1
  83. package/lib/lang/transform-ratchet.spec.d.ts +1 -0
  84. package/lib/lang/transform-ratchet.spec.js +118 -0
  85. package/lib/logger/classic-single-line-log-message-formatter.d.ts +6 -0
  86. package/{dist/types → lib}/logger/log-message-builder.d.ts +2 -2
  87. package/{dist/es → lib}/logger/log-message-builder.js +1 -0
  88. package/{dist/types → lib}/logger/log-message-formatter.d.ts +2 -2
  89. package/lib/logger/log-message-formatter.js +1 -0
  90. package/{dist/types → lib}/logger/log-message-processor.d.ts +1 -1
  91. package/lib/logger/log-message-processor.js +1 -0
  92. package/{dist/types → lib}/logger/log-message.d.ts +1 -1
  93. package/lib/logger/log-message.js +1 -0
  94. package/{dist/types → lib}/logger/log-snapshot.d.ts +1 -1
  95. package/lib/logger/log-snapshot.js +1 -0
  96. package/{dist/types → lib}/logger/logger-instance.d.ts +6 -6
  97. package/{dist/es → lib}/logger/logger-instance.js +15 -8
  98. package/{dist/types → lib}/logger/logger-meta.d.ts +1 -1
  99. package/lib/logger/logger-meta.js +1 -0
  100. package/{dist/types → lib}/logger/logger-options.d.ts +4 -4
  101. package/lib/logger/logger-options.js +1 -0
  102. package/{dist/types → lib}/logger/logger-ring-buffer.d.ts +2 -2
  103. package/{dist/es → lib}/logger/logger-ring-buffer.js +7 -6
  104. package/{dist/types → lib}/logger/logger-util.d.ts +2 -2
  105. package/{dist/es → lib}/logger/logger-util.js +10 -10
  106. package/lib/logger/logger-util.spec.d.ts +1 -0
  107. package/lib/logger/logger-util.spec.js +9 -0
  108. package/{dist/types → lib}/logger/logger.d.ts +7 -16
  109. package/{dist/es → lib}/logger/logger.js +14 -14
  110. package/lib/logger/logger.spec.d.ts +1 -0
  111. package/lib/logger/logger.spec.js +134 -0
  112. package/lib/logger/none-log-message-formatter.d.ts +6 -0
  113. package/lib/logger/structured-json-log-message-formatter.d.ts +6 -0
  114. package/{dist/types → lib}/network/browser-local-ip-provider.d.ts +1 -1
  115. package/{dist/es → lib}/network/browser-local-ip-provider.js +3 -3
  116. package/lib/network/browser-local-ip-provider.spec.d.ts +1 -0
  117. package/lib/network/browser-local-ip-provider.spec.js +16 -0
  118. package/{dist/types → lib}/network/fixed-local-ip-provider.d.ts +1 -1
  119. package/{dist/es → lib}/network/fixed-local-ip-provider.js +1 -0
  120. package/lib/network/local-ip-provider.d.ts +3 -0
  121. package/lib/network/local-ip-provider.js +1 -0
  122. package/{dist/types → lib}/network/network-ratchet.d.ts +1 -1
  123. package/{dist/es → lib}/network/network-ratchet.js +2 -2
  124. package/lib/network/network-ratchet.spec.d.ts +1 -0
  125. package/lib/network/network-ratchet.spec.js +13 -0
  126. package/{dist/types → lib}/stream/buffer-writable.d.ts +2 -2
  127. package/{dist/es → lib}/stream/buffer-writable.js +1 -1
  128. package/lib/stream/multi-stream.d.ts +7 -0
  129. package/lib/stream/multi-stream.js +12 -0
  130. package/{dist/types → lib}/stream/stream-ratchet.d.ts +2 -2
  131. package/{dist/es → lib}/stream/stream-ratchet.js +2 -2
  132. package/lib/stream/stream-ratchet.spec.d.ts +1 -0
  133. package/lib/stream/stream-ratchet.spec.js +13 -0
  134. package/{dist/types → lib}/stream/string-writable.d.ts +1 -1
  135. package/{dist/es → lib}/stream/string-writable.js +1 -1
  136. package/lib/stream/string-writable.spec.d.ts +1 -0
  137. package/lib/stream/string-writable.spec.js +12 -0
  138. package/{dist/es → lib}/third-party/google/google-recaptcha-ratchet.js +3 -3
  139. package/lib/third-party/google/google-recaptcha-ratchet.spec.d.ts +1 -0
  140. package/lib/third-party/google/google-recaptcha-ratchet.spec.js +20 -0
  141. package/{dist/types → lib}/third-party/twilio/twilio-ratchet.d.ts +0 -4
  142. package/{dist/es → lib}/third-party/twilio/twilio-ratchet.js +8 -5
  143. package/{dist/types → lib}/transform/built-in-transforms.d.ts +1 -1
  144. package/{dist/es → lib}/transform/built-in-transforms.js +2 -2
  145. package/lib/transform/transform-rule.js +1 -0
  146. package/{dist/types → lib}/tx/transaction-configuration.d.ts +2 -2
  147. package/lib/tx/transaction-configuration.js +1 -0
  148. package/{dist/types → lib}/tx/transaction-ratchet.d.ts +3 -3
  149. package/{dist/es → lib}/tx/transaction-ratchet.js +4 -4
  150. package/lib/tx/transaction-ratchet.spec.d.ts +1 -0
  151. package/lib/tx/transaction-ratchet.spec.js +130 -0
  152. package/{dist/types → lib}/tx/transaction-result.d.ts +1 -1
  153. package/lib/tx/transaction-result.js +1 -0
  154. package/lib/tx/transaction-step.js +1 -0
  155. package/package.json +11 -12
  156. package/dist/cjs/2d/line-2d.js +0 -2
  157. package/dist/cjs/2d/plane-2d.js +0 -2
  158. package/dist/cjs/2d/point-2d.js +0 -2
  159. package/dist/cjs/2d/poly-line-2d.js +0 -2
  160. package/dist/cjs/2d/ratchet-2d.js +0 -250
  161. package/dist/cjs/build/build-information.js +0 -2
  162. package/dist/cjs/build/ratchet-common-info.js +0 -18
  163. package/dist/cjs/histogram/histogram-entry.js +0 -2
  164. package/dist/cjs/histogram/histogram.js +0 -54
  165. package/dist/cjs/index.js +0 -74
  166. package/dist/cjs/jwt/common-jwt-token.js +0 -2
  167. package/dist/cjs/jwt/expired-jwt-handling.js +0 -9
  168. package/dist/cjs/jwt/jwt-ratchet-like.js +0 -2
  169. package/dist/cjs/jwt/jwt-ratchet.js +0 -164
  170. package/dist/cjs/jwt/jwt-token-base.js +0 -2
  171. package/dist/cjs/lang/array-ratchet.js +0 -87
  172. package/dist/cjs/lang/base64-ratchet.js +0 -49
  173. package/dist/cjs/lang/boolean-ratchet.js +0 -49
  174. package/dist/cjs/lang/composite-last-success-provider.js +0 -28
  175. package/dist/cjs/lang/date-ratchet.js +0 -33
  176. package/dist/cjs/lang/duration-ratchet.js +0 -46
  177. package/dist/cjs/lang/enum-ratchet.js +0 -34
  178. package/dist/cjs/lang/error-ratchet.js +0 -49
  179. package/dist/cjs/lang/expiring-object.js +0 -68
  180. package/dist/cjs/lang/geolocation-ratchet.js +0 -267
  181. package/dist/cjs/lang/global-ratchet.js +0 -48
  182. package/dist/cjs/lang/key-value.js +0 -6
  183. package/dist/cjs/lang/last-success-provider.js +0 -2
  184. package/dist/cjs/lang/map-ratchet.js +0 -168
  185. package/dist/cjs/lang/no.js +0 -8
  186. package/dist/cjs/lang/number-ratchet.js +0 -159
  187. package/dist/cjs/lang/parsed-url.js +0 -2
  188. package/dist/cjs/lang/promise-ratchet.js +0 -142
  189. package/dist/cjs/lang/require-ratchet.js +0 -60
  190. package/dist/cjs/lang/stop-watch.js +0 -117
  191. package/dist/cjs/lang/string-ratchet.js +0 -195
  192. package/dist/cjs/lang/time-zone-ratchet.js +0 -80
  193. package/dist/cjs/lang/timeout-token.js +0 -19
  194. package/dist/cjs/lang/transform-ratchet.js +0 -70
  195. package/dist/cjs/logger/classic-single-line-log-message-formatter.js +0 -18
  196. package/dist/cjs/logger/log-message-builder.js +0 -51
  197. package/dist/cjs/logger/log-message-format-type.js +0 -9
  198. package/dist/cjs/logger/log-message-formatter.js +0 -2
  199. package/dist/cjs/logger/log-message-processor.js +0 -2
  200. package/dist/cjs/logger/log-message.js +0 -2
  201. package/dist/cjs/logger/log-snapshot.js +0 -2
  202. package/dist/cjs/logger/logger-instance.js +0 -207
  203. package/dist/cjs/logger/logger-level-name.js +0 -12
  204. package/dist/cjs/logger/logger-meta.js +0 -2
  205. package/dist/cjs/logger/logger-options.js +0 -2
  206. package/dist/cjs/logger/logger-output-function.js +0 -9
  207. package/dist/cjs/logger/logger-ring-buffer.js +0 -76
  208. package/dist/cjs/logger/logger-util.js +0 -49
  209. package/dist/cjs/logger/logger.js +0 -139
  210. package/dist/cjs/logger/none-log-message-formatter.js +0 -9
  211. package/dist/cjs/logger/structured-json-log-message-formatter.js +0 -24
  212. package/dist/cjs/network/browser-local-ip-provider.js +0 -25
  213. package/dist/cjs/network/fixed-local-ip-provider.js +0 -12
  214. package/dist/cjs/network/local-ip-provider.js +0 -2
  215. package/dist/cjs/network/network-ratchet.js +0 -106
  216. package/dist/cjs/stream/buffer-writable.js +0 -20
  217. package/dist/cjs/stream/stream-ratchet.js +0 -72
  218. package/dist/cjs/stream/string-writable.js +0 -18
  219. package/dist/cjs/third-party/google/google-recaptcha-ratchet.js +0 -33
  220. package/dist/cjs/third-party/twilio/twilio-ratchet.js +0 -75
  221. package/dist/cjs/transform/built-in-transforms.js +0 -195
  222. package/dist/cjs/transform/transform-rule.js +0 -2
  223. package/dist/cjs/tx/transaction-configuration.js +0 -2
  224. package/dist/cjs/tx/transaction-final-state.js +0 -9
  225. package/dist/cjs/tx/transaction-ratchet.js +0 -80
  226. package/dist/cjs/tx/transaction-result.js +0 -2
  227. package/dist/cjs/tx/transaction-step.js +0 -2
  228. package/dist/es/index.js +0 -71
  229. package/dist/tsconfig.cjs.tsbuildinfo +0 -1
  230. package/dist/tsconfig.es.tsbuildinfo +0 -1
  231. package/dist/tsconfig.types.tsbuildinfo +0 -1
  232. package/dist/types/index.d.ts +0 -74
  233. package/dist/types/jwt/common-jwt-token.d.ts +0 -17
  234. package/dist/types/lang/array-ratchet.d.ts +0 -30
  235. package/dist/types/lang/enum-ratchet.d.ts +0 -12
  236. package/dist/types/lang/last-success-provider.d.ts +0 -4
  237. package/dist/types/lang/promise-ratchet.d.ts +0 -32
  238. package/dist/types/lang/time-zone-ratchet.d.ts +0 -50
  239. package/dist/types/logger/classic-single-line-log-message-formatter.d.ts +0 -6
  240. package/dist/types/logger/none-log-message-formatter.d.ts +0 -6
  241. package/dist/types/logger/structured-json-log-message-formatter.d.ts +0 -6
  242. package/dist/types/network/local-ip-provider.d.ts +0 -4
  243. /package/{dist/es → lib}/2d/line-2d.js +0 -0
  244. /package/{dist/types → lib}/2d/plane-2d.d.ts +0 -0
  245. /package/{dist/es → lib}/2d/plane-2d.js +0 -0
  246. /package/{dist/types → lib}/2d/point-2d.d.ts +0 -0
  247. /package/{dist/es → lib}/2d/point-2d.js +0 -0
  248. /package/{dist/es → lib}/2d/poly-line-2d.js +0 -0
  249. /package/{dist/es/build/build-information.js → lib/2d/ratchet-2d.spec.d.ts} +0 -0
  250. /package/{dist/types → lib}/build/build-information.d.ts +0 -0
  251. /package/{dist/es/histogram/histogram-entry.js → lib/build/build-information.js} +0 -0
  252. /package/{dist/es → lib}/build/ratchet-common-info.js +0 -0
  253. /package/{dist/types → lib}/histogram/histogram-entry.d.ts +0 -0
  254. /package/{dist/es/jwt/common-jwt-token.js → lib/histogram/histogram-entry.js} +0 -0
  255. /package/{dist/es/jwt/jwt-ratchet-like.js → lib/histogram/histogram.spec.d.ts} +0 -0
  256. /package/{dist/es/jwt/jwt-token-base.js → lib/index.d.ts} +0 -0
  257. /package/{dist/es/lang/last-success-provider.js → lib/index.js} +0 -0
  258. /package/{dist/es/lang/parsed-url.js → lib/jwt/common-jwt-token.js} +0 -0
  259. /package/{dist/types → lib}/jwt/expired-jwt-handling.d.ts +0 -0
  260. /package/{dist/es → lib}/jwt/expired-jwt-handling.js +0 -0
  261. /package/{dist/es/logger/log-message-formatter.js → lib/jwt/jwt-ratchet-like.js} +0 -0
  262. /package/{dist/es/logger/log-message-processor.js → lib/jwt/jwt-ratchet.spec.d.ts} +0 -0
  263. /package/{dist/es/logger/log-message.js → lib/jwt/jwt-token-base.js} +0 -0
  264. /package/{dist/es/logger/log-snapshot.js → lib/lang/array-ratchet.spec.d.ts} +0 -0
  265. /package/{dist/es/logger/logger-meta.js → lib/lang/base64-ratchet.spec.d.ts} +0 -0
  266. /package/{dist/types → lib}/lang/boolean-ratchet.d.ts +0 -0
  267. /package/{dist/es/logger/logger-options.js → lib/lang/boolean-ratchet.spec.d.ts} +0 -0
  268. /package/{dist/es/network/local-ip-provider.js → lib/lang/composite-last-success-provider.spec.d.ts} +0 -0
  269. /package/{dist/types → lib}/lang/date-ratchet.d.ts +0 -0
  270. /package/{dist/es/transform/transform-rule.js → lib/lang/date-ratchet.spec.d.ts} +0 -0
  271. /package/{dist/types → lib}/lang/duration-ratchet.d.ts +0 -0
  272. /package/{dist/es/tx/transaction-configuration.js → lib/lang/duration-ratchet.spec.d.ts} +0 -0
  273. /package/{dist/types → lib}/lang/error-ratchet.d.ts +0 -0
  274. /package/{dist/es/tx/transaction-result.js → lib/lang/error-ratchet.spec.d.ts} +0 -0
  275. /package/{dist/es/tx/transaction-step.js → lib/lang/expiring-object.spec.d.ts} +0 -0
  276. /package/{dist/types → lib}/lang/geolocation-ratchet.d.ts +0 -0
  277. /package/{dist/types → lib}/lang/global-ratchet.d.ts +0 -0
  278. /package/{dist/types → lib}/lang/key-value.d.ts +0 -0
  279. /package/{dist/types → lib}/lang/no.d.ts +0 -0
  280. /package/{dist/es → lib}/lang/no.js +0 -0
  281. /package/{dist/types → lib}/lang/number-ratchet.d.ts +0 -0
  282. /package/{dist/types → lib}/lang/parsed-url.d.ts +0 -0
  283. /package/{dist/types → lib}/lang/require-ratchet.d.ts +0 -0
  284. /package/{dist/types → lib}/lang/string-ratchet.d.ts +0 -0
  285. /package/{dist/es → lib}/logger/classic-single-line-log-message-formatter.js +0 -0
  286. /package/{dist/types → lib}/logger/log-message-format-type.d.ts +0 -0
  287. /package/{dist/es → lib}/logger/log-message-format-type.js +0 -0
  288. /package/{dist/types → lib}/logger/logger-level-name.d.ts +0 -0
  289. /package/{dist/es → lib}/logger/logger-level-name.js +0 -0
  290. /package/{dist/types → lib}/logger/logger-output-function.d.ts +0 -0
  291. /package/{dist/es → lib}/logger/logger-output-function.js +0 -0
  292. /package/{dist/es → lib}/logger/none-log-message-formatter.js +0 -0
  293. /package/{dist/es → lib}/logger/structured-json-log-message-formatter.js +0 -0
  294. /package/{dist/types → lib}/third-party/google/google-recaptcha-ratchet.d.ts +0 -0
  295. /package/{dist/types → lib}/transform/transform-rule.d.ts +0 -0
  296. /package/{dist/types → lib}/tx/transaction-final-state.d.ts +0 -0
  297. /package/{dist/es → lib}/tx/transaction-final-state.js +0 -0
  298. /package/{dist/types → lib}/tx/transaction-step.d.ts +0 -0
@@ -1,49 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ErrorRatchet = void 0;
4
- const tslib_1 = require("tslib");
5
- const logger_1 = require("../logger/logger");
6
- const util_1 = tslib_1.__importDefault(require("util"));
7
- class ErrorRatchet {
8
- static safeStringifyErr(err, log = true) {
9
- let rval = 'ERR WAS NULL';
10
- if (err) {
11
- if (err['message']) {
12
- rval = err['message'];
13
- }
14
- else {
15
- try {
16
- rval = JSON.stringify(err);
17
- }
18
- catch (err2) {
19
- logger_1.Logger.error('Failed to json stringify');
20
- rval = String(err);
21
- }
22
- }
23
- }
24
- if (log) {
25
- logger_1.Logger.error('%s', rval, err);
26
- }
27
- return rval;
28
- }
29
- static asErr(input) {
30
- let rval = null;
31
- if (input) {
32
- if (input instanceof Error) {
33
- rval = input;
34
- }
35
- else {
36
- rval = new Error('Force-Cast to error : ' + String(input));
37
- }
38
- }
39
- return rval;
40
- }
41
- static fErr(format, ...input) {
42
- const msg = util_1.default.format(format, ...input);
43
- return new Error(msg);
44
- }
45
- static throwFormattedErr(format, ...input) {
46
- throw ErrorRatchet.fErr(format, ...input);
47
- }
48
- }
49
- exports.ErrorRatchet = ErrorRatchet;
@@ -1,68 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ExpiringObjectConfig = exports.ExpiringObject = void 0;
4
- const logger_1 = require("../logger/logger");
5
- const error_ratchet_1 = require("./error-ratchet");
6
- const logger_level_name_1 = require("../logger/logger-level-name");
7
- class ExpiringObject {
8
- constructor(inputConfig) {
9
- this._config = Object.assign({}, this.defaultConfig(), inputConfig || {});
10
- if (this._config.overrideTimeRemainingMS && this._config.timeToLiveMS) {
11
- error_ratchet_1.ErrorRatchet.throwFormattedErr('Cannot define both time to live and overrideTimeRemainingMS');
12
- }
13
- if (!this._config.overrideTimeRemainingMS && !this._config.timeToLiveMS) {
14
- error_ratchet_1.ErrorRatchet.throwFormattedErr('Must define exactly one of timeToLiveMS or overrideTimeRemainingMS');
15
- }
16
- if (this._config.initialValue) {
17
- this.update(this._config.initialValue);
18
- }
19
- this._timeRemainingMS = this._config.overrideTimeRemainingMS || this.defaultTimeRemainingMS;
20
- }
21
- defaultConfig() {
22
- const rval = {
23
- generator: null,
24
- initialValue: null,
25
- logLevel: logger_level_name_1.LoggerLevelName.debug,
26
- overrideTimeRemainingMS: null,
27
- timeToLiveMS: 1000 * 60,
28
- };
29
- return rval;
30
- }
31
- async defaultTimeRemainingMS(lastUpdatedEpochMS) {
32
- let rval = 0;
33
- if (lastUpdatedEpochMS) {
34
- const ageMS = new Date().getTime() - lastUpdatedEpochMS;
35
- rval = Math.max(0, this._config.timeToLiveMS - ageMS);
36
- }
37
- return rval;
38
- }
39
- update(newValue, doNotUpdateClock = false) {
40
- this._cacheObject = newValue;
41
- if (!doNotUpdateClock) {
42
- this._lastUpdatedEpochMS = new Date().getTime();
43
- }
44
- logger_1.Logger.logByLevel(this._config.logLevel, 'Updated cache value to %j', newValue);
45
- }
46
- async fetchCacheObjectTimeRemainingMS() {
47
- return this._timeRemainingMS(this._lastUpdatedEpochMS);
48
- }
49
- async fetch() {
50
- const remainMS = await this._timeRemainingMS(this._lastUpdatedEpochMS);
51
- if (!remainMS) {
52
- this._cacheObject = null;
53
- this._lastUpdatedEpochMS = null;
54
- }
55
- if (!this._cacheObject) {
56
- if (this._config.generator) {
57
- const newValue = await this._config.generator();
58
- logger_1.Logger.logByLevel(this._config.logLevel, 'Auto call to generator returned %j', newValue);
59
- this.update(newValue);
60
- }
61
- }
62
- return this._cacheObject;
63
- }
64
- }
65
- exports.ExpiringObject = ExpiringObject;
66
- class ExpiringObjectConfig {
67
- }
68
- exports.ExpiringObjectConfig = ExpiringObjectConfig;
@@ -1,267 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.GeolocationRatchet = void 0;
4
- const require_ratchet_1 = require("./require-ratchet");
5
- const number_ratchet_1 = require("./number-ratchet");
6
- const error_ratchet_1 = require("./error-ratchet");
7
- const logger_1 = require("../logger/logger");
8
- class GeolocationRatchet {
9
- constructor() { }
10
- static distanceBetweenLocations(lat1, lon1, lat2, lon2, unit = 'M') {
11
- const uU = !!unit ? unit.toUpperCase() : '';
12
- if (['M', 'K', 'N', 'F', 'E'].indexOf(uU) === -1) {
13
- throw new Error('Invalid unit');
14
- }
15
- if (lat1 == lat2 && lon1 == lon2) {
16
- return 0;
17
- }
18
- else {
19
- const radlat1 = (Math.PI * lat1) / 180;
20
- const radlat2 = (Math.PI * lat2) / 180;
21
- const theta = lon1 - lon2;
22
- const radtheta = (Math.PI * theta) / 180;
23
- let dist = Math.sin(radlat1) * Math.sin(radlat2) + Math.cos(radlat1) * Math.cos(radlat2) * Math.cos(radtheta);
24
- if (dist > 1) {
25
- dist = 1;
26
- }
27
- dist = Math.acos(dist);
28
- dist = (dist * 180) / Math.PI;
29
- dist = dist * 60 * 1.1515;
30
- if (uU === 'F') {
31
- dist *= 5280;
32
- }
33
- if (uU === 'K') {
34
- dist *= 1.609344;
35
- }
36
- if (uU === 'E') {
37
- dist *= 1609.344;
38
- }
39
- if (uU === 'N') {
40
- dist *= 0.8684;
41
- }
42
- return dist;
43
- }
44
- }
45
- static distanceBetweenRatchetGeoLocations(loc1, loc2, unit = 'M') {
46
- return GeolocationRatchet.distanceBetweenLocations(loc1.lat, loc1.lng, loc2.lat, loc2.lng, unit);
47
- }
48
- static degreeOfLatLngInMiles(latitudeInDecimalDegress = 0) {
49
- const latInRads = (latitudeInDecimalDegress * Math.PI) / 180;
50
- const cosLat = Math.cos(latInRads);
51
- const rval = number_ratchet_1.NumberRatchet.safeNumber((cosLat * 69.172).toFixed(4));
52
- return rval;
53
- }
54
- static milesInDegLatLng(miles, latitudeInDecimalDegress = 0) {
55
- require_ratchet_1.RequireRatchet.notNullOrUndefined(miles);
56
- require_ratchet_1.RequireRatchet.true(miles >= 0);
57
- const degreeInMiles = GeolocationRatchet.degreeOfLatLngInMiles(latitudeInDecimalDegress);
58
- return miles / degreeInMiles;
59
- }
60
- static centerOfBounds(bounds) {
61
- require_ratchet_1.RequireRatchet.notNullOrUndefined(bounds);
62
- return {
63
- lat: (bounds.extent.lat + bounds.origin.lat) / 2,
64
- lng: (bounds.extent.lng + bounds.origin.lng) / 2,
65
- };
66
- }
67
- static calculateSplits(input, slices, field) {
68
- require_ratchet_1.RequireRatchet.notNullOrUndefined(input);
69
- require_ratchet_1.RequireRatchet.notNullOrUndefined(slices);
70
- require_ratchet_1.RequireRatchet.notNullOrUndefined(field);
71
- input.sort((a, b) => a.origin[field] - b.origin[field]);
72
- const centers = input.map((i) => GeolocationRatchet.centerOfBounds(i));
73
- const vals = centers.map((c) => c[field]);
74
- const splits = [];
75
- for (let i = 1; i < vals.length; i++) {
76
- const size = vals[i] - vals[i - 1];
77
- if (splits.length < slices) {
78
- splits.push({ idx: i, size: size });
79
- splits.sort((a, b) => a.size - b.size);
80
- }
81
- else if (size > splits[0].size) {
82
- splits[0] = { idx: i, size: size };
83
- splits.sort((a, b) => a.size - b.size);
84
- }
85
- else {
86
- logger_1.Logger.silly('Skipping, size : %d, %j', size, splits);
87
- }
88
- }
89
- logger_1.Logger.info('Splits at : %j', splits);
90
- splits.sort((a, b) => a.idx - b.idx);
91
- return splits;
92
- }
93
- static clusterGeoBounds(inputVal, latSlices = 2, lngSlices = 5) {
94
- let rval = null;
95
- if (latSlices * lngSlices < 2) {
96
- error_ratchet_1.ErrorRatchet.throwFormattedErr('Cannot set slices to less than 2 : %d x %d', latSlices, lngSlices);
97
- }
98
- if (!!inputVal) {
99
- rval = [];
100
- const input = Object.assign([], inputVal);
101
- input.sort((a, b) => a.origin.lng - b.origin.lng);
102
- const lngSplits = GeolocationRatchet.calculateSplits(inputVal, lngSlices - 1, 'lng');
103
- lngSplits.sort((a, b) => a.idx - b.idx);
104
- for (let i = 0; i <= lngSplits.length; i++) {
105
- const lngStartIdx = i === 0 ? 0 : lngSplits[i - 1].idx;
106
- const lngEndIdx = i === lngSplits.length ? input.length : lngSplits[i].idx;
107
- const lngBatch = input.slice(lngStartIdx, lngEndIdx);
108
- lngBatch.sort((a, b) => a.origin.lat - b.origin.lat);
109
- const latSplits = GeolocationRatchet.calculateSplits(lngBatch, latSlices - 1, 'lat');
110
- for (let j = 0; j <= latSplits.length; j++) {
111
- const latStartIdx = j == 0 ? 0 : latSplits[j - 1].idx;
112
- const latEndIdx = j === latSplits.length ? lngBatch.length : latSplits[j].idx;
113
- const latBatch = lngBatch.slice(latStartIdx, latEndIdx);
114
- rval.push(GeolocationRatchet.combineBounds(latBatch));
115
- }
116
- }
117
- logger_1.Logger.info('New bounds : %j', rval);
118
- }
119
- return rval;
120
- }
121
- static canonicalizeBounds(inp, allowCrossover = false) {
122
- require_ratchet_1.RequireRatchet.notNullOrUndefined(inp, 'RatchetLocationBounds');
123
- const minLat = Math.min(inp.extent.lat, inp.origin.lat);
124
- const maxLat = Math.max(inp.extent.lat, inp.origin.lat);
125
- const minLng = Math.min(inp.extent.lng, inp.origin.lng);
126
- const maxLng = Math.max(inp.extent.lng, inp.origin.lng);
127
- const latXover = (minLat < 0 && maxLat > 0) || (minLat > 0 && maxLat < 0);
128
- const lngXover = (minLat < 0 && maxLat > 0) || (minLat > 0 && maxLat < 0);
129
- if (latXover || lngXover) {
130
- if (allowCrossover) {
131
- return inp;
132
- }
133
- else {
134
- throw new Error('Cannot canonicalize, bounds crosses over boundary');
135
- }
136
- }
137
- const rval = {
138
- origin: {
139
- lat: minLat,
140
- lng: minLng,
141
- },
142
- extent: {
143
- lat: maxLat,
144
- lng: maxLng,
145
- },
146
- };
147
- return rval;
148
- }
149
- static combineBounds(inp) {
150
- let rval = null;
151
- if (inp && inp.length > 0) {
152
- rval = {
153
- origin: {
154
- lat: inp.map((i) => i.origin.lat).reduce((a, i) => Math.min(a, i)),
155
- lng: inp.map((i) => i.origin.lng).reduce((a, i) => Math.min(a, i)),
156
- },
157
- extent: {
158
- lat: inp.map((i) => i.extent.lat).reduce((a, i) => Math.max(a, i)),
159
- lng: inp.map((i) => i.extent.lng).reduce((a, i) => Math.max(a, i)),
160
- },
161
- };
162
- }
163
- return rval;
164
- }
165
- static roundLocation(r, roundDigits) {
166
- return {
167
- lat: number_ratchet_1.NumberRatchet.safeNumber(r.lat.toFixed(roundDigits)),
168
- lng: number_ratchet_1.NumberRatchet.safeNumber(r.lng.toFixed(roundDigits)),
169
- };
170
- }
171
- static locationToBounds(loc, radiusMiles) {
172
- const offset = GeolocationRatchet.milesInDegLatLng(radiusMiles, loc.lat);
173
- const gfb = {
174
- origin: {
175
- lat: loc.lat - offset,
176
- lng: loc.lng - offset,
177
- },
178
- extent: {
179
- lat: loc.lat + offset,
180
- lng: loc.lng + offset,
181
- },
182
- };
183
- return gfb;
184
- }
185
- static sameLocation(loc1, loc2) {
186
- return !!loc1 && !!loc2 && loc1.lat === loc2.lat && loc1.lng === loc2.lng;
187
- }
188
- static pointInBounds(pt, bound) {
189
- return (!!pt &&
190
- !!bound &&
191
- number_ratchet_1.NumberRatchet.between(pt.lat, bound.origin.lat, bound.extent.lat) &&
192
- number_ratchet_1.NumberRatchet.between(pt.lng, bound.origin.lng, bound.extent.lng));
193
- }
194
- static pointInAnyBound(pt, inBounds, minPointsBeforeMapping = 10) {
195
- let rval = false;
196
- if (inBounds.length > minPointsBeforeMapping) {
197
- const mp = GeolocationRatchet.buildRatchetLocationBoundsMap(inBounds);
198
- rval = GeolocationRatchet.pointInRatchetLocationBoundsMap(pt, mp);
199
- }
200
- else {
201
- for (let i = 0; i < inBounds.length && !rval; i++) {
202
- rval = GeolocationRatchet.pointInBounds(pt, inBounds[i]);
203
- }
204
- }
205
- return rval;
206
- }
207
- static pointInRatchetLocationBoundsMap(pt, mp) {
208
- let rval = false;
209
- const entry = GeolocationRatchet.findRatchetLocationBoundsMapEntry(pt, mp);
210
- if (!!entry) {
211
- const bounds = entry.bounds;
212
- for (let i = 0; i < bounds.length && !rval; i++) {
213
- rval = GeolocationRatchet.pointInBounds(pt, bounds[i]);
214
- }
215
- }
216
- return rval;
217
- }
218
- static findRatchetLocationBoundsMapEntry(pt, mp) {
219
- let rval = null;
220
- if (pt.lat >= mp.latOffset && pt.lat <= mp.maxLat && pt.lng >= mp.lngOffset && pt.lng <= mp.maxLng) {
221
- const ltIdx = Math.trunc(pt.lat) - mp.latOffset;
222
- const lngIdx = Math.trunc(pt.lng) - mp.lngOffset;
223
- rval = mp.mapping[ltIdx][lngIdx];
224
- }
225
- return rval;
226
- }
227
- static buildRatchetLocationBoundsMap(inBounds) {
228
- const minLat = inBounds.map((i) => i.origin.lat).reduce((a, i) => Math.min(a, i));
229
- const minLng = inBounds.map((i) => i.origin.lng).reduce((a, i) => Math.min(a, i));
230
- const maxLat = inBounds.map((i) => i.extent.lat).reduce((a, i) => Math.max(a, i));
231
- const maxLng = inBounds.map((i) => i.extent.lng).reduce((a, i) => Math.max(a, i));
232
- const latOffset = Math.trunc(minLat) - 1;
233
- const lngOffset = Math.trunc(minLng) - 1;
234
- const latEntries = Math.trunc(maxLat) - latOffset + 1;
235
- const lngEntries = Math.trunc(maxLng) - lngOffset + 1;
236
- const mapping = [];
237
- for (let i = 0; i < latEntries; i++) {
238
- const newRow = [];
239
- for (let j = 0; j < lngEntries; j++) {
240
- newRow.push({
241
- lat: latOffset + i,
242
- lng: lngOffset + j,
243
- bounds: [],
244
- });
245
- }
246
- mapping.push(newRow);
247
- }
248
- inBounds.forEach((b) => {
249
- for (let i = Math.trunc(b.origin.lat); i <= Math.trunc(b.extent.lat); i++) {
250
- const latIdx = i - latOffset;
251
- const row = mapping[latIdx];
252
- for (let j = Math.trunc(b.origin.lng); j <= Math.trunc(b.extent.lng); j++) {
253
- const lngIdx = j - lngOffset;
254
- row[lngIdx].bounds.push(b);
255
- }
256
- }
257
- });
258
- return {
259
- latOffset: latOffset,
260
- lngOffset: lngOffset,
261
- maxLat: latOffset + latEntries,
262
- maxLng: lngOffset + lngEntries,
263
- mapping: mapping,
264
- };
265
- }
266
- }
267
- exports.GeolocationRatchet = GeolocationRatchet;
@@ -1,48 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.GlobalRatchet = void 0;
4
- const error_ratchet_1 = require("./error-ratchet");
5
- const require_ratchet_1 = require("./require-ratchet");
6
- const logger_1 = require("../logger/logger");
7
- class GlobalRatchet {
8
- constructor() { }
9
- static fetchGlobalRecord(returnNullOnNone) {
10
- var _a;
11
- let rval = null;
12
- if (process === null || process === void 0 ? void 0 : process.env) {
13
- logger_1.Logger.silly('Using process.env as global');
14
- rval = process.env;
15
- }
16
- else if ((_a = global === null || global === void 0 ? void 0 : global.process) === null || _a === void 0 ? void 0 : _a.env) {
17
- logger_1.Logger.silly('Using global.process.env as global');
18
- rval = global.process.env;
19
- }
20
- else if (global) {
21
- logger_1.Logger.silly('Using process.env as global');
22
- rval = global;
23
- }
24
- if (!rval) {
25
- if (returnNullOnNone) {
26
- logger_1.Logger.silly('Returning null as global');
27
- rval = null;
28
- }
29
- else {
30
- throw error_ratchet_1.ErrorRatchet.fErr('Could not find process.env OR global in scope');
31
- }
32
- }
33
- return rval;
34
- }
35
- static fetchGlobalVar(envVar) {
36
- require_ratchet_1.RequireRatchet.notNullOrUndefined(envVar, 'envVar');
37
- const myGlobal = GlobalRatchet.fetchGlobalRecord();
38
- const value = myGlobal[envVar];
39
- return value;
40
- }
41
- static setGlobalVar(envVar, value) {
42
- require_ratchet_1.RequireRatchet.notNullOrUndefined(envVar, 'envVar');
43
- require_ratchet_1.RequireRatchet.notNullOrUndefined(value, 'value');
44
- const myGlobal = GlobalRatchet.fetchGlobalRecord();
45
- myGlobal[envVar] = value;
46
- }
47
- }
48
- exports.GlobalRatchet = GlobalRatchet;
@@ -1,6 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.KeyValue = void 0;
4
- class KeyValue {
5
- }
6
- exports.KeyValue = KeyValue;
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,168 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.MapRatchet = void 0;
4
- const logger_1 = require("../logger/logger");
5
- const error_ratchet_1 = require("./error-ratchet");
6
- const lodash_1 = require("lodash");
7
- class MapRatchet {
8
- static expandNestedKeys(src) {
9
- const rval = {};
10
- Object.keys(src).forEach((k) => {
11
- (0, lodash_1.set)(rval, k, src[k]);
12
- });
13
- return rval;
14
- }
15
- static mapByUniqueProperty(input, propName) {
16
- if (!input || !propName) {
17
- throw new Error('Neither input nor propName can be null');
18
- }
19
- const rval = new Map();
20
- input.forEach((i) => {
21
- const val = !!i ? i[propName] : null;
22
- if (val === null || val === undefined) {
23
- throw new Error('No value for ' + propName + ' found in ' + JSON.stringify(i));
24
- }
25
- if (rval.has(val)) {
26
- throw new Error('Multiple values found for ' + val);
27
- }
28
- rval.set(val, i);
29
- });
30
- return rval;
31
- }
32
- static groupByProperty(input, propName) {
33
- if (!input || !propName) {
34
- throw new Error('Neither input nor propName can be null');
35
- }
36
- const rval = new Map();
37
- input.forEach((i) => {
38
- const val = !!i ? i[propName] : null;
39
- if (val === null || val === undefined) {
40
- throw error_ratchet_1.ErrorRatchet.fErr('No value for %s found in %j', propName, i);
41
- }
42
- if (!rval.has(val)) {
43
- rval.set(val, []);
44
- }
45
- rval.get(val).push(i);
46
- });
47
- return rval;
48
- }
49
- static findValue(toSearch, path) {
50
- if (!path || path.length == 0) {
51
- return toSearch;
52
- }
53
- else {
54
- if (toSearch) {
55
- return MapRatchet.findValue(toSearch[path[0]], path.slice(1));
56
- }
57
- else {
58
- return null;
59
- }
60
- }
61
- }
62
- static findValueDotPath(toSearch, dotPath) {
63
- if (!dotPath || dotPath.length == 0) {
64
- return toSearch;
65
- }
66
- else {
67
- if (toSearch) {
68
- return MapRatchet.findValue(toSearch, dotPath.split('.'));
69
- }
70
- else {
71
- return null;
72
- }
73
- }
74
- }
75
- static simpleDeepCompare(object1, object2) {
76
- if (object1 == null && object2 == null)
77
- return true;
78
- if (object1 == null || object2 == null)
79
- return false;
80
- return JSON.stringify(object1) == JSON.stringify(object2);
81
- }
82
- static toKeyValueList(value) {
83
- const returnArray = [];
84
- for (const k of Object.keys(value)) {
85
- returnArray.push({
86
- key: k,
87
- value: value[k],
88
- });
89
- }
90
- return returnArray;
91
- }
92
- static fromKeyValueList(list) {
93
- const rval = {};
94
- list.forEach((a) => (rval[a.key] = a.value));
95
- return rval;
96
- }
97
- static cleanup(obj, stripZero = false, stripNull = true, stripUndefined = true, stripEmptyString = true) {
98
- if (obj === null || obj === undefined || typeof obj !== 'object') {
99
- return obj;
100
- }
101
- const o = JSON.parse(JSON.stringify(obj));
102
- Object.keys(o).forEach((key) => {
103
- if (o[key] && typeof o[key] === 'object') {
104
- if (Array.isArray(o[key])) {
105
- for (let i = 0; i < o[key].length; i++) {
106
- o[key][i] = MapRatchet.cleanup(o[key][i]);
107
- }
108
- }
109
- else {
110
- o[key] = MapRatchet.cleanup(o[key]);
111
- }
112
- }
113
- else if ((o[key] === undefined && stripUndefined) ||
114
- (o[key] === null && stripNull) ||
115
- (o[key] === '' && stripEmptyString) ||
116
- (o[key] === 0 && stripZero)) {
117
- delete o[key];
118
- }
119
- else {
120
- o[key] = o[key];
121
- }
122
- });
123
- return o;
124
- }
125
- static extractValueFromMapIgnoreCase(src, key) {
126
- let rval = null;
127
- if (src && key) {
128
- const finder = key.toLowerCase();
129
- Object.keys(src).forEach((s) => {
130
- if (s.toLowerCase() === finder) {
131
- const newVal = src[s];
132
- if (rval) {
133
- logger_1.Logger.warn('Multiple entries found for %s (replacing %s with %s', key, rval, newVal);
134
- }
135
- rval = newVal;
136
- }
137
- });
138
- }
139
- return rval;
140
- }
141
- static safeCallFunction(ob, fnName) {
142
- let rval = false;
143
- if (!!ob && !!ob[fnName] && typeof ob[fnName] === 'function') {
144
- try {
145
- ob[fnName]();
146
- rval = true;
147
- }
148
- catch (err) {
149
- logger_1.Logger.warn('Error calling %s on %s : %s', fnName, ob, err, err);
150
- }
151
- }
152
- return rval;
153
- }
154
- static caseInsensitiveAccess(ob, keyName) {
155
- let rval = null;
156
- if (!!ob && !!keyName) {
157
- rval = ob[keyName];
158
- if (!rval) {
159
- const keyNameCI = Object.keys(ob).find((f) => f.toLowerCase() === keyName.toLowerCase());
160
- if (!!keyNameCI) {
161
- rval = ob[keyNameCI];
162
- }
163
- }
164
- }
165
- return rval;
166
- }
167
- }
168
- exports.MapRatchet = MapRatchet;
@@ -1,8 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.No = void 0;
4
- class No {
5
- static op(...args) {
6
- }
7
- }
8
- exports.No = No;