@venizia/ignis-helpers 0.4.0 → 0.4.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (273) hide show
  1. package/dist/cjs/common/constants/duration.d.ts +4 -1
  2. package/dist/cjs/common/constants/duration.d.ts.map +1 -1
  3. package/dist/cjs/common/constants/duration.js +13 -8
  4. package/dist/cjs/common/constants/duration.js.map +1 -1
  5. package/dist/cjs/common/redact.js +1 -1
  6. package/dist/cjs/common/redact.js.map +1 -1
  7. package/dist/cjs/modules/base.js +1 -1
  8. package/dist/cjs/modules/base.js.map +1 -1
  9. package/dist/cjs/modules/crypto/algorithms/aes.algorithm.js +1 -1
  10. package/dist/cjs/modules/crypto/algorithms/aes.algorithm.js.map +1 -1
  11. package/dist/cjs/modules/env/app-env.d.ts.map +1 -1
  12. package/dist/cjs/modules/env/app-env.js +1 -1
  13. package/dist/cjs/modules/env/app-env.js.map +1 -1
  14. package/dist/cjs/modules/logger/common/constants.js +1 -1
  15. package/dist/cjs/modules/logger/common/constants.js.map +1 -1
  16. package/dist/cjs/modules/logger/factory.js +1 -1
  17. package/dist/cjs/modules/logger/factory.js.map +1 -1
  18. package/dist/cjs/modules/logger/formatting/deep-splat.js +1 -1
  19. package/dist/cjs/modules/logger/formatting/deep-splat.js.map +1 -1
  20. package/dist/cjs/modules/logger/formatting/error-prettier.js +4 -4
  21. package/dist/cjs/modules/logger/formatting/error-prettier.js.map +1 -1
  22. package/dist/cjs/modules/logger/hf/flusher.js +3 -3
  23. package/dist/cjs/modules/logger/hf/flusher.js.map +1 -1
  24. package/dist/cjs/modules/logger/hf/logger.d.ts.map +1 -1
  25. package/dist/cjs/modules/logger/hf/logger.js +3 -1
  26. package/dist/cjs/modules/logger/hf/logger.js.map +1 -1
  27. package/dist/cjs/modules/logger/resolver.js +3 -3
  28. package/dist/cjs/modules/logger/resolver.js.map +1 -1
  29. package/dist/cjs/modules/logger/winston/formatters/deep-splat.js +1 -1
  30. package/dist/cjs/modules/logger/winston/formatters/deep-splat.js.map +1 -1
  31. package/dist/cjs/modules/logger/winston/logger-factory.js +1 -1
  32. package/dist/cjs/modules/logger/winston/logger-factory.js.map +1 -1
  33. package/dist/cjs/modules/logger/winston/transports/dgram.transport.js +2 -2
  34. package/dist/cjs/modules/logger/winston/transports/dgram.transport.js.map +1 -1
  35. package/dist/cjs/modules/network/http-request/fetcher/axios-fetcher.js +1 -1
  36. package/dist/cjs/modules/network/http-request/fetcher/axios-fetcher.js.map +1 -1
  37. package/dist/cjs/modules/network/http-request/fetcher/base-fetcher.d.ts +17 -14
  38. package/dist/cjs/modules/network/http-request/fetcher/base-fetcher.d.ts.map +1 -1
  39. package/dist/cjs/modules/network/http-request/fetcher/base-fetcher.js +3 -0
  40. package/dist/cjs/modules/network/http-request/fetcher/base-fetcher.js.map +1 -1
  41. package/dist/cjs/modules/network/http-request/fetcher/node-fetcher.d.ts +13 -4
  42. package/dist/cjs/modules/network/http-request/fetcher/node-fetcher.d.ts.map +1 -1
  43. package/dist/cjs/modules/network/http-request/fetcher/node-fetcher.js +34 -11
  44. package/dist/cjs/modules/network/http-request/fetcher/node-fetcher.js.map +1 -1
  45. package/dist/cjs/modules/network/tcp-socket/base-tcp-client.helper.js +1 -1
  46. package/dist/cjs/modules/network/tcp-socket/base-tcp-client.helper.js.map +1 -1
  47. package/dist/cjs/modules/network/tcp-socket/base-tcp-server.helper.d.ts.map +1 -1
  48. package/dist/cjs/modules/network/tcp-socket/base-tcp-server.helper.js +7 -6
  49. package/dist/cjs/modules/network/tcp-socket/base-tcp-server.helper.js.map +1 -1
  50. package/dist/cjs/modules/network/udp-socket/network-udp-client.helper.js +1 -1
  51. package/dist/cjs/modules/network/udp-socket/network-udp-client.helper.js.map +1 -1
  52. package/dist/cjs/modules/network/utilities/query-string.d.ts +27 -2
  53. package/dist/cjs/modules/network/utilities/query-string.d.ts.map +1 -1
  54. package/dist/cjs/modules/network/utilities/query-string.js +34 -2
  55. package/dist/cjs/modules/network/utilities/query-string.js.map +1 -1
  56. package/dist/cjs/modules/network/utilities/url-safety/ingest.js +1 -1
  57. package/dist/cjs/modules/network/utilities/url-safety/ingest.js.map +1 -1
  58. package/dist/cjs/modules/network/utilities/url-safety/policy.js +1 -1
  59. package/dist/cjs/modules/network/utilities/url-safety/policy.js.map +1 -1
  60. package/dist/cjs/modules/pool/abstract.js +4 -4
  61. package/dist/cjs/modules/pool/abstract.js.map +1 -1
  62. package/dist/cjs/modules/queue/bullmq/helper.js +2 -2
  63. package/dist/cjs/modules/queue/bullmq/helper.js.map +1 -1
  64. package/dist/cjs/modules/queue/kafka/bundler/platformatic-require.plugin.js.map +1 -1
  65. package/dist/cjs/modules/queue/kafka/bundler/platformatic-wasm.plugin.js +1 -1
  66. package/dist/cjs/modules/queue/kafka/bundler/platformatic-wasm.plugin.js.map +1 -1
  67. package/dist/cjs/modules/queue/kafka/consumer.js +2 -2
  68. package/dist/cjs/modules/queue/kafka/consumer.js.map +1 -1
  69. package/dist/cjs/modules/queue/mqtt/helper.js +4 -4
  70. package/dist/cjs/modules/queue/mqtt/helper.js.map +1 -1
  71. package/dist/cjs/modules/redis/base/abstract.helper.js +4 -4
  72. package/dist/cjs/modules/redis/base/abstract.helper.js.map +1 -1
  73. package/dist/cjs/modules/redis/cluster/cluster.helper.js +1 -1
  74. package/dist/cjs/modules/redis/cluster/cluster.helper.js.map +1 -1
  75. package/dist/cjs/modules/redis/sentinel/sentinel.helper.js +1 -1
  76. package/dist/cjs/modules/redis/sentinel/sentinel.helper.js.map +1 -1
  77. package/dist/cjs/modules/secrets/base/abstract.helper.d.ts.map +1 -1
  78. package/dist/cjs/modules/secrets/base/abstract.helper.js +7 -3
  79. package/dist/cjs/modules/secrets/base/abstract.helper.js.map +1 -1
  80. package/dist/cjs/modules/secrets/hashicorp/hashicorp.helper.js +2 -2
  81. package/dist/cjs/modules/secrets/hashicorp/hashicorp.helper.js.map +1 -1
  82. package/dist/cjs/modules/socket/socket-io/browser.d.ts +5 -0
  83. package/dist/cjs/modules/socket/socket-io/browser.d.ts.map +1 -0
  84. package/dist/cjs/modules/socket/socket-io/browser.js +21 -0
  85. package/dist/cjs/modules/socket/socket-io/browser.js.map +1 -0
  86. package/dist/cjs/modules/socket/socket-io/client/browser-helper.d.ts +61 -0
  87. package/dist/cjs/modules/socket/socket-io/client/browser-helper.d.ts.map +1 -0
  88. package/dist/cjs/modules/socket/socket-io/client/browser-helper.js +250 -0
  89. package/dist/cjs/modules/socket/socket-io/client/browser-helper.js.map +1 -0
  90. package/dist/cjs/modules/socket/socket-io/client/helper.d.ts +8 -51
  91. package/dist/cjs/modules/socket/socket-io/client/helper.d.ts.map +1 -1
  92. package/dist/cjs/modules/socket/socket-io/client/helper.js +12 -230
  93. package/dist/cjs/modules/socket/socket-io/client/helper.js.map +1 -1
  94. package/dist/cjs/modules/socket/socket-io/server/helper.js +5 -5
  95. package/dist/cjs/modules/socket/socket-io/server/helper.js.map +1 -1
  96. package/dist/cjs/modules/socket/websocket/server/delivery.js +2 -2
  97. package/dist/cjs/modules/socket/websocket/server/delivery.js.map +1 -1
  98. package/dist/cjs/modules/socket/websocket/server/helper.js +4 -4
  99. package/dist/cjs/modules/socket/websocket/server/helper.js.map +1 -1
  100. package/dist/cjs/modules/storage/base.js +3 -3
  101. package/dist/cjs/modules/storage/base.js.map +1 -1
  102. package/dist/cjs/modules/storage/bun-s3/helper.js +1 -1
  103. package/dist/cjs/modules/storage/bun-s3/helper.js.map +1 -1
  104. package/dist/cjs/modules/storage/bun-s3/utility.js +6 -6
  105. package/dist/cjs/modules/storage/bun-s3/utility.js.map +1 -1
  106. package/dist/cjs/modules/storage/common/errors.js +1 -1
  107. package/dist/cjs/modules/storage/common/errors.js.map +1 -1
  108. package/dist/cjs/modules/storage/minio/helper.js +4 -4
  109. package/dist/cjs/modules/storage/minio/helper.js.map +1 -1
  110. package/dist/cjs/modules/temporal/abstract.js +5 -5
  111. package/dist/cjs/modules/temporal/abstract.js.map +1 -1
  112. package/dist/cjs/modules/temporal/adapters/intl.d.ts.map +1 -1
  113. package/dist/cjs/modules/temporal/adapters/intl.js +3 -1
  114. package/dist/cjs/modules/temporal/adapters/intl.js.map +1 -1
  115. package/dist/cjs/modules/temporal/locale/locale.js +4 -4
  116. package/dist/cjs/modules/temporal/locale/locale.js.map +1 -1
  117. package/dist/cjs/modules/tree/builder.js +2 -2
  118. package/dist/cjs/modules/tree/builder.js.map +1 -1
  119. package/dist/cjs/modules/uid/opaque.js +2 -2
  120. package/dist/cjs/modules/uid/opaque.js.map +1 -1
  121. package/dist/cjs/modules/uid/uuid/v5.js +1 -1
  122. package/dist/cjs/modules/uid/uuid/v5.js.map +1 -1
  123. package/dist/cjs/modules/worker-thread/bus/base.js +4 -4
  124. package/dist/cjs/modules/worker-thread/bus/base.js.map +1 -1
  125. package/dist/cjs/modules/worker-thread/thread/base.js +2 -2
  126. package/dist/cjs/modules/worker-thread/thread/base.js.map +1 -1
  127. package/dist/cjs/modules/worker-thread/worker/base.js +4 -4
  128. package/dist/cjs/modules/worker-thread/worker/base.js.map +1 -1
  129. package/dist/cjs/utilities/parse.utility.js +4 -4
  130. package/dist/cjs/utilities/parse.utility.js.map +1 -1
  131. package/dist/cjs/utilities/promise.utility.js +1 -1
  132. package/dist/cjs/utilities/promise.utility.js.map +1 -1
  133. package/dist/cjs/utilities/request.utility.js +1 -1
  134. package/dist/cjs/utilities/request.utility.js.map +1 -1
  135. package/dist/cjs/utilities/sleep.utility.js +1 -1
  136. package/dist/cjs/utilities/sleep.utility.js.map +1 -1
  137. package/dist/esm/common/constants/duration.d.ts +4 -1
  138. package/dist/esm/common/constants/duration.d.ts.map +1 -1
  139. package/dist/esm/common/constants/duration.js +13 -8
  140. package/dist/esm/common/constants/duration.js.map +1 -1
  141. package/dist/esm/common/redact.js +1 -1
  142. package/dist/esm/common/redact.js.map +1 -1
  143. package/dist/esm/modules/base.js +1 -1
  144. package/dist/esm/modules/base.js.map +1 -1
  145. package/dist/esm/modules/crypto/algorithms/aes.algorithm.js +1 -1
  146. package/dist/esm/modules/crypto/algorithms/aes.algorithm.js.map +1 -1
  147. package/dist/esm/modules/env/app-env.d.ts.map +1 -1
  148. package/dist/esm/modules/env/app-env.js +1 -1
  149. package/dist/esm/modules/env/app-env.js.map +1 -1
  150. package/dist/esm/modules/logger/common/constants.js +1 -1
  151. package/dist/esm/modules/logger/common/constants.js.map +1 -1
  152. package/dist/esm/modules/logger/factory.js +1 -1
  153. package/dist/esm/modules/logger/factory.js.map +1 -1
  154. package/dist/esm/modules/logger/formatting/deep-splat.js +1 -1
  155. package/dist/esm/modules/logger/formatting/deep-splat.js.map +1 -1
  156. package/dist/esm/modules/logger/formatting/error-prettier.js +4 -4
  157. package/dist/esm/modules/logger/formatting/error-prettier.js.map +1 -1
  158. package/dist/esm/modules/logger/hf/flusher.js +3 -3
  159. package/dist/esm/modules/logger/hf/flusher.js.map +1 -1
  160. package/dist/esm/modules/logger/hf/logger.d.ts.map +1 -1
  161. package/dist/esm/modules/logger/hf/logger.js +3 -1
  162. package/dist/esm/modules/logger/hf/logger.js.map +1 -1
  163. package/dist/esm/modules/logger/resolver.js +3 -3
  164. package/dist/esm/modules/logger/resolver.js.map +1 -1
  165. package/dist/esm/modules/logger/winston/formatters/deep-splat.js +1 -1
  166. package/dist/esm/modules/logger/winston/formatters/deep-splat.js.map +1 -1
  167. package/dist/esm/modules/logger/winston/logger-factory.js +1 -1
  168. package/dist/esm/modules/logger/winston/logger-factory.js.map +1 -1
  169. package/dist/esm/modules/logger/winston/transports/dgram.transport.js +2 -2
  170. package/dist/esm/modules/logger/winston/transports/dgram.transport.js.map +1 -1
  171. package/dist/esm/modules/network/http-request/fetcher/axios-fetcher.js +1 -1
  172. package/dist/esm/modules/network/http-request/fetcher/axios-fetcher.js.map +1 -1
  173. package/dist/esm/modules/network/http-request/fetcher/base-fetcher.d.ts +17 -14
  174. package/dist/esm/modules/network/http-request/fetcher/base-fetcher.d.ts.map +1 -1
  175. package/dist/esm/modules/network/http-request/fetcher/base-fetcher.js +3 -0
  176. package/dist/esm/modules/network/http-request/fetcher/base-fetcher.js.map +1 -1
  177. package/dist/esm/modules/network/http-request/fetcher/node-fetcher.d.ts +13 -4
  178. package/dist/esm/modules/network/http-request/fetcher/node-fetcher.d.ts.map +1 -1
  179. package/dist/esm/modules/network/http-request/fetcher/node-fetcher.js +36 -13
  180. package/dist/esm/modules/network/http-request/fetcher/node-fetcher.js.map +1 -1
  181. package/dist/esm/modules/network/tcp-socket/base-tcp-client.helper.js +1 -1
  182. package/dist/esm/modules/network/tcp-socket/base-tcp-client.helper.js.map +1 -1
  183. package/dist/esm/modules/network/tcp-socket/base-tcp-server.helper.d.ts.map +1 -1
  184. package/dist/esm/modules/network/tcp-socket/base-tcp-server.helper.js +7 -6
  185. package/dist/esm/modules/network/tcp-socket/base-tcp-server.helper.js.map +1 -1
  186. package/dist/esm/modules/network/udp-socket/network-udp-client.helper.js +1 -1
  187. package/dist/esm/modules/network/udp-socket/network-udp-client.helper.js.map +1 -1
  188. package/dist/esm/modules/network/utilities/query-string.d.ts +27 -2
  189. package/dist/esm/modules/network/utilities/query-string.d.ts.map +1 -1
  190. package/dist/esm/modules/network/utilities/query-string.js +31 -1
  191. package/dist/esm/modules/network/utilities/query-string.js.map +1 -1
  192. package/dist/esm/modules/network/utilities/url-safety/ingest.js +1 -1
  193. package/dist/esm/modules/network/utilities/url-safety/ingest.js.map +1 -1
  194. package/dist/esm/modules/network/utilities/url-safety/policy.js +1 -1
  195. package/dist/esm/modules/network/utilities/url-safety/policy.js.map +1 -1
  196. package/dist/esm/modules/pool/abstract.js +4 -4
  197. package/dist/esm/modules/pool/abstract.js.map +1 -1
  198. package/dist/esm/modules/queue/bullmq/helper.js +2 -2
  199. package/dist/esm/modules/queue/bullmq/helper.js.map +1 -1
  200. package/dist/esm/modules/queue/kafka/bundler/platformatic-require.plugin.js.map +1 -1
  201. package/dist/esm/modules/queue/kafka/bundler/platformatic-wasm.plugin.js +1 -1
  202. package/dist/esm/modules/queue/kafka/bundler/platformatic-wasm.plugin.js.map +1 -1
  203. package/dist/esm/modules/queue/kafka/consumer.js +2 -2
  204. package/dist/esm/modules/queue/kafka/consumer.js.map +1 -1
  205. package/dist/esm/modules/queue/mqtt/helper.js +4 -4
  206. package/dist/esm/modules/queue/mqtt/helper.js.map +1 -1
  207. package/dist/esm/modules/redis/base/abstract.helper.js +4 -4
  208. package/dist/esm/modules/redis/base/abstract.helper.js.map +1 -1
  209. package/dist/esm/modules/redis/cluster/cluster.helper.js +1 -1
  210. package/dist/esm/modules/redis/cluster/cluster.helper.js.map +1 -1
  211. package/dist/esm/modules/redis/sentinel/sentinel.helper.js +1 -1
  212. package/dist/esm/modules/redis/sentinel/sentinel.helper.js.map +1 -1
  213. package/dist/esm/modules/secrets/base/abstract.helper.d.ts.map +1 -1
  214. package/dist/esm/modules/secrets/base/abstract.helper.js +7 -3
  215. package/dist/esm/modules/secrets/base/abstract.helper.js.map +1 -1
  216. package/dist/esm/modules/secrets/hashicorp/hashicorp.helper.js +2 -2
  217. package/dist/esm/modules/secrets/hashicorp/hashicorp.helper.js.map +1 -1
  218. package/dist/esm/modules/socket/socket-io/browser.d.ts +5 -0
  219. package/dist/esm/modules/socket/socket-io/browser.d.ts.map +1 -0
  220. package/dist/esm/modules/socket/socket-io/browser.js +5 -0
  221. package/dist/esm/modules/socket/socket-io/browser.js.map +1 -0
  222. package/dist/esm/modules/socket/socket-io/client/browser-helper.d.ts +61 -0
  223. package/dist/esm/modules/socket/socket-io/client/browser-helper.d.ts.map +1 -0
  224. package/dist/esm/modules/socket/socket-io/client/browser-helper.js +246 -0
  225. package/dist/esm/modules/socket/socket-io/client/browser-helper.js.map +1 -0
  226. package/dist/esm/modules/socket/socket-io/client/helper.d.ts +8 -51
  227. package/dist/esm/modules/socket/socket-io/client/helper.d.ts.map +1 -1
  228. package/dist/esm/modules/socket/socket-io/client/helper.js +12 -230
  229. package/dist/esm/modules/socket/socket-io/client/helper.js.map +1 -1
  230. package/dist/esm/modules/socket/socket-io/server/helper.js +5 -5
  231. package/dist/esm/modules/socket/socket-io/server/helper.js.map +1 -1
  232. package/dist/esm/modules/socket/websocket/server/delivery.js +2 -2
  233. package/dist/esm/modules/socket/websocket/server/delivery.js.map +1 -1
  234. package/dist/esm/modules/socket/websocket/server/helper.js +4 -4
  235. package/dist/esm/modules/socket/websocket/server/helper.js.map +1 -1
  236. package/dist/esm/modules/storage/base.js +3 -3
  237. package/dist/esm/modules/storage/base.js.map +1 -1
  238. package/dist/esm/modules/storage/bun-s3/helper.js +1 -1
  239. package/dist/esm/modules/storage/bun-s3/helper.js.map +1 -1
  240. package/dist/esm/modules/storage/bun-s3/utility.js +6 -6
  241. package/dist/esm/modules/storage/bun-s3/utility.js.map +1 -1
  242. package/dist/esm/modules/storage/common/errors.js +1 -1
  243. package/dist/esm/modules/storage/common/errors.js.map +1 -1
  244. package/dist/esm/modules/storage/minio/helper.js +4 -4
  245. package/dist/esm/modules/storage/minio/helper.js.map +1 -1
  246. package/dist/esm/modules/temporal/abstract.js +5 -5
  247. package/dist/esm/modules/temporal/abstract.js.map +1 -1
  248. package/dist/esm/modules/temporal/adapters/intl.d.ts.map +1 -1
  249. package/dist/esm/modules/temporal/adapters/intl.js +3 -1
  250. package/dist/esm/modules/temporal/adapters/intl.js.map +1 -1
  251. package/dist/esm/modules/temporal/locale/locale.js +4 -4
  252. package/dist/esm/modules/temporal/locale/locale.js.map +1 -1
  253. package/dist/esm/modules/tree/builder.js +2 -2
  254. package/dist/esm/modules/tree/builder.js.map +1 -1
  255. package/dist/esm/modules/uid/opaque.js +2 -2
  256. package/dist/esm/modules/uid/opaque.js.map +1 -1
  257. package/dist/esm/modules/uid/uuid/v5.js +1 -1
  258. package/dist/esm/modules/uid/uuid/v5.js.map +1 -1
  259. package/dist/esm/modules/worker-thread/bus/base.js +4 -4
  260. package/dist/esm/modules/worker-thread/bus/base.js.map +1 -1
  261. package/dist/esm/modules/worker-thread/thread/base.js +2 -2
  262. package/dist/esm/modules/worker-thread/thread/base.js.map +1 -1
  263. package/dist/esm/modules/worker-thread/worker/base.js +4 -4
  264. package/dist/esm/modules/worker-thread/worker/base.js.map +1 -1
  265. package/dist/esm/utilities/parse.utility.js +4 -4
  266. package/dist/esm/utilities/parse.utility.js.map +1 -1
  267. package/dist/esm/utilities/promise.utility.js +1 -1
  268. package/dist/esm/utilities/promise.utility.js.map +1 -1
  269. package/dist/esm/utilities/request.utility.js +1 -1
  270. package/dist/esm/utilities/request.utility.js.map +1 -1
  271. package/dist/esm/utilities/sleep.utility.js +1 -1
  272. package/dist/esm/utilities/sleep.utility.js.map +1 -1
  273. package/package.json +10 -4
@@ -74,11 +74,14 @@ export declare class DurationMultipliers {
74
74
  static readonly MONTH: number;
75
75
  static readonly YEAR: number;
76
76
  static readonly BY_UNIT: Record<string, number>;
77
+ /** The multiplier of a known unit, `null` for anything else - inherited property names included. */
78
+ private static multiplierOf;
77
79
  /**
78
80
  * `null` rather than a throw, so a caller that wants an error raises its own with its own context.
79
81
  * Every method here answers the same way.
80
82
  *
81
- * One map read, not a validity check followed by a read: an unknown unit is already `undefined`.
83
+ * The unit is checked against {@link DurationUnits.SCHEME_SET} first: a plain-object read alone
84
+ * would answer `'constructor'` or `'toString'` with a member of `Object.prototype`, not `undefined`.
82
85
  */
83
86
  static toMilliseconds(opts: IDuration | null): number | null;
84
87
  /** The inverse of {@link toMilliseconds}. Fractional on purpose - rounding here would silently lose a 36-hour window asked for in days. */
@@ -1 +1 @@
1
- {"version":3,"file":"duration.d.ts","sourceRoot":"","sources":["../../../../src/common/constants/duration.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,WAAW,EAAE,MAAM,UAAU,CAAC;AAE5C,qEAAqE;AACrE,qBAAa,aAAa;IACxB,MAAM,CAAC,QAAQ,CAAC,WAAW,iBAAiB;IAC5C,MAAM,CAAC,QAAQ,CAAC,MAAM,YAAY;IAClC,MAAM,CAAC,QAAQ,CAAC,MAAM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,CAAC,IAAI,EAAE;QAAE,YAAY,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,aAAa,CAAA;KAAE,GAAG,MAAM,GAAG,IAAI;IAU3F,qGAAqG;IACrG,MAAM,CAAC,OAAO,CAAC,IAAI,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,aAAa,CAAC;QAAC,EAAE,EAAE,aAAa,CAAA;KAAE,GAAG,MAAM,GAAG,IAAI;IAW9F,2JAA2J;IAC3J,MAAM,CAAC,KAAK,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,GAAG,IAAI;IAqB7C,qGAAqG;IACrG,MAAM,CAAC,mBAAmB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI;CAGzD"}
@@ -119,35 +119,40 @@ class DurationMultipliers {
119
119
  [DurationUnits.MONTH]: this.MONTH,
120
120
  [DurationUnits.YEAR]: this.YEAR,
121
121
  }; }
122
+ /** The multiplier of a known unit, `null` for anything else - inherited property names included. */
123
+ static multiplierOf(unit) {
124
+ return typeof unit === 'string' && DurationUnits.isValid(unit) ? this.BY_UNIT[unit] : null;
125
+ }
122
126
  /**
123
127
  * `null` rather than a throw, so a caller that wants an error raises its own with its own context.
124
128
  * Every method here answers the same way.
125
129
  *
126
- * One map read, not a validity check followed by a read: an unknown unit is already `undefined`.
130
+ * The unit is checked against {@link DurationUnits.SCHEME_SET} first: a plain-object read alone
131
+ * would answer `'constructor'` or `'toString'` with a member of `Object.prototype`, not `undefined`.
127
132
  */
128
133
  static toMilliseconds(opts) {
129
134
  if (!opts) {
130
135
  return null;
131
136
  }
132
- const multiplier = this.BY_UNIT[opts.unit];
133
- if (multiplier === undefined || !Number.isFinite(opts.value)) {
137
+ const multiplier = this.multiplierOf(opts.unit);
138
+ if (multiplier === null || !Number.isFinite(opts.value)) {
134
139
  return null;
135
140
  }
136
141
  return Math.round(opts.value * multiplier);
137
142
  }
138
143
  /** The inverse of {@link toMilliseconds}. Fractional on purpose - rounding here would silently lose a 36-hour window asked for in days. */
139
144
  static fromMilliseconds(opts) {
140
- const multiplier = this.BY_UNIT[opts?.unit];
141
- if (multiplier === undefined || !Number.isFinite(opts.milliseconds)) {
145
+ const multiplier = this.multiplierOf(opts?.unit);
146
+ if (multiplier === null || !Number.isFinite(opts.milliseconds)) {
142
147
  return null;
143
148
  }
144
149
  return opts.milliseconds / multiplier;
145
150
  }
146
151
  /** Unit to unit, through milliseconds. Fractional, for the reason {@link fromMilliseconds} gives. */
147
152
  static convert(opts) {
148
- const source = this.BY_UNIT[opts?.from];
149
- const target = this.BY_UNIT[opts?.to];
150
- if (source === undefined || target === undefined || !Number.isFinite(opts.value)) {
153
+ const source = this.multiplierOf(opts?.from);
154
+ const target = this.multiplierOf(opts?.to);
155
+ if (source === null || target === null || !Number.isFinite(opts.value)) {
151
156
  return null;
152
157
  }
153
158
  return (opts.value * source) / target;
@@ -1 +1 @@
1
- {"version":3,"file":"duration.js","sourceRoot":"","sources":["../../../../src/common/constants/duration.ts"],"names":[],"mappings":";;;AAEA,qEAAqE;AACrE,MAAa,aAAa;aACR,gBAAW,GAAG,aAAa,CAAC;aAC5B,WAAM,GAAG,QAAQ,CAAC;aAClB,WAAM,GAAG,QAAQ,CAAC;aAClB,SAAI,GAAG,MAAM,CAAC;aACd,QAAG,GAAG,KAAK,CAAC;aACZ,SAAI,GAAG,MAAM,CAAC;aACd,UAAK,GAAG,OAAO,CAAC;aAChB,SAAI,GAAG,MAAM,CAAC;aAEd,eAAU,GAAG,IAAI,GAAG,CAAC;QACnC,IAAI,CAAC,WAAW;QAChB,IAAI,CAAC,MAAM;QACX,IAAI,CAAC,MAAM;QACX,IAAI,CAAC,IAAI;QACT,IAAI,CAAC,GAAG;QACR,IAAI,CAAC,IAAI;QACT,IAAI,CAAC,KAAK;QACV,IAAI,CAAC,IAAI;KACV,CAAC,CAAC;IAEH,MAAM,CAAC,OAAO,CAAC,KAAa;QAC1B,OAAO,IAAI,CAAC,UAAU,CAAC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CAAC;QAEjC,IAAI,CAAC,IAAI,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC;YACrC,OAAO,IAAI,CAAC;QACd,CAAC;QAED,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC;IACzB,CAAC;IAED,qGAAqG;IACrG,MAAM,CAAC,mBAAmB,CAAC,KAAa;QACtC,OAAO,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC;IAChD,CAAC;;AAzFH,kDA0FC","sourcesContent":["import { type TConstValue } from '../types';\n\n/** The time units a duration can be expressed in, smallest first. */\nexport class DurationUnits {\n static readonly MILLISECOND = 'millisecond';\n static readonly SECOND = 'second';\n static readonly MINUTE = 'minute';\n static readonly HOUR = 'hour';\n static readonly DAY = 'day';\n static readonly WEEK = 'week';\n static readonly MONTH = 'month';\n static readonly YEAR = 'year';\n\n static readonly SCHEME_SET = new Set([\n this.MILLISECOND,\n this.SECOND,\n this.MINUTE,\n this.HOUR,\n this.DAY,\n this.WEEK,\n this.MONTH,\n this.YEAR,\n ]);\n\n static isValid(input: string): input is TDurationUnit {\n return this.SCHEME_SET.has(input);\n }\n}\n\nexport type TDurationUnit = TConstValue<typeof DurationUnits>;\n\n/**\n * Written spellings that resolve to a unit. Member names are the spelling, upper-cased - so\n * {@link resolve} upper-cases its input and reads one property, with no second table to keep in step.\n *\n * `M` is MINUTE and `MO` is MONTH - the same choice every duration library makes, and the one\n * ambiguity a reader will trip on. There is no single-letter month.\n */\nexport class DurationAliases {\n static readonly MS = DurationUnits.MILLISECOND;\n static readonly MSEC = DurationUnits.MILLISECOND;\n static readonly MILLISECOND = DurationUnits.MILLISECOND;\n static readonly MILLISECONDS = DurationUnits.MILLISECOND;\n\n static readonly S = DurationUnits.SECOND;\n static readonly SEC = DurationUnits.SECOND;\n static readonly SECOND = DurationUnits.SECOND;\n static readonly SECONDS = DurationUnits.SECOND;\n\n static readonly M = DurationUnits.MINUTE;\n static readonly MIN = DurationUnits.MINUTE;\n static readonly MINUTE = DurationUnits.MINUTE;\n static readonly MINUTES = DurationUnits.MINUTE;\n\n static readonly H = DurationUnits.HOUR;\n static readonly HR = DurationUnits.HOUR;\n static readonly HOUR = DurationUnits.HOUR;\n static readonly HOURS = DurationUnits.HOUR;\n\n static readonly D = DurationUnits.DAY;\n static readonly DAY = DurationUnits.DAY;\n static readonly DAYS = DurationUnits.DAY;\n\n static readonly W = DurationUnits.WEEK;\n static readonly WK = DurationUnits.WEEK;\n static readonly WEEK = DurationUnits.WEEK;\n static readonly WEEKS = DurationUnits.WEEK;\n\n static readonly MO = DurationUnits.MONTH;\n static readonly MON = DurationUnits.MONTH;\n static readonly MONTH = DurationUnits.MONTH;\n static readonly MONTHS = DurationUnits.MONTH;\n\n static readonly Y = DurationUnits.YEAR;\n static readonly YR = DurationUnits.YEAR;\n static readonly YEAR = DurationUnits.YEAR;\n static readonly YEARS = DurationUnits.YEAR;\n\n /** Resolves a written unit - `'d'`, `'days'`, `'DAY'` - to its canonical name, or `null`. */\n static resolve(input: string): TDurationUnit | null {\n if (typeof input !== 'string') {\n return null;\n }\n\n // Try the input as given first. `trim().toUpperCase()` allocates two strings and costs ~55ns,\n // where the lookup itself is ~1ns - so the spellings callers actually pass (`'day'`, `'d'`,\n // `'DAYS'`) must not pay for it. Measured, both ways.\n //\n // The table is declared below because it is derived FROM this class; it is read at call time,\n // never at class-evaluation time.\n /* eslint-disable @typescript-eslint/no-use-before-define */\n return ALIAS_LOOKUP.get(input) ?? ALIAS_LOOKUP.get(input.trim().toUpperCase()) ?? null;\n /* eslint-enable @typescript-eslint/no-use-before-define */\n }\n}\n\n/**\n * Derived from the class once, never hand-listed, so the two cannot drift. Reading the class\n * directly is slower and would need `name`/`length`/`constructor` guarded out. Each spelling is\n * stored upper and lower so the common call allocates nothing.\n */\nconst ALIAS_LOOKUP: Map<string, TDurationUnit> = new Map(\n Object.entries(DurationAliases)\n .filter((entry): entry is [string, TDurationUnit] => DurationUnits.isValid(entry[1] as string))\n .flatMap(([spelling, unit]): Array<[string, TDurationUnit]> => [\n [spelling, unit],\n [spelling.toLowerCase(), unit],\n ]),\n);\n\nexport interface IDuration {\n unit: TDurationUnit;\n value: number;\n}\n\n/** `30d`, `1500 ms`, `-2 Hours`. One number, optional space, one unit. */\nconst DURATION_PATTERN = /^([+-]?\\d+(?:\\.\\d+)?)\\s*([a-z]+)$/i;\n\n/**\n * A month is 30 days and a year 365, nominal. These size a WINDOW - a grace period, a cache TTL, a\n * near-expiry horizon - and must never compute a calendar date: adding `MONTH` to 31 January lands\n * on 2 March in a leap year and 3 March otherwise. Use a date library for calendar arithmetic.\n */\nexport class DurationMultipliers {\n static readonly MILLISECOND = 1;\n static readonly SECOND = 1000 * this.MILLISECOND;\n static readonly MINUTE = 60 * this.SECOND;\n static readonly HOUR = 60 * this.MINUTE;\n static readonly DAY = 24 * this.HOUR;\n static readonly WEEK = 7 * this.DAY;\n static readonly MONTH = 30 * this.DAY;\n static readonly YEAR = 365 * this.DAY;\n\n static readonly BY_UNIT: Record<string, number> = {\n [DurationUnits.MILLISECOND]: this.MILLISECOND,\n [DurationUnits.SECOND]: this.SECOND,\n [DurationUnits.MINUTE]: this.MINUTE,\n [DurationUnits.HOUR]: this.HOUR,\n [DurationUnits.DAY]: this.DAY,\n [DurationUnits.WEEK]: this.WEEK,\n [DurationUnits.MONTH]: this.MONTH,\n [DurationUnits.YEAR]: this.YEAR,\n };\n\n /**\n * `null` rather than a throw, so a caller that wants an error raises its own with its own context.\n * Every method here answers the same way.\n *\n * One map read, not a validity check followed by a read: an unknown unit is already `undefined`.\n */\n static toMilliseconds(opts: IDuration | null): number | null {\n if (!opts) {\n return null;\n }\n\n const multiplier = this.BY_UNIT[opts.unit];\n\n if (multiplier === undefined || !Number.isFinite(opts.value)) {\n return null;\n }\n\n return Math.round(opts.value * multiplier);\n }\n\n /** The inverse of {@link toMilliseconds}. Fractional on purpose - rounding here would silently lose a 36-hour window asked for in days. */\n static fromMilliseconds(opts: { milliseconds: number; unit: TDurationUnit }): number | null {\n const multiplier = this.BY_UNIT[opts?.unit];\n\n if (multiplier === undefined || !Number.isFinite(opts.milliseconds)) {\n return null;\n }\n\n return opts.milliseconds / multiplier;\n }\n\n /** Unit to unit, through milliseconds. Fractional, for the reason {@link fromMilliseconds} gives. */\n static convert(opts: { value: number; from: TDurationUnit; to: TDurationUnit }): number | null {\n const source = this.BY_UNIT[opts?.from];\n const target = this.BY_UNIT[opts?.to];\n\n if (source === undefined || target === undefined || !Number.isFinite(opts.value)) {\n return null;\n }\n\n return (opts.value * source) / target;\n }\n\n /** Reads a written duration - `'30d'`, `'1500 ms'`, `'2 hours'` - into {@link IDuration}. Aliases and the `M`/`MO` rule are on {@link DurationAliases}. */\n static parse(input: string): IDuration | null {\n if (typeof input !== 'string') {\n return null;\n }\n\n const matched = DURATION_PATTERN.exec(input.trim());\n\n if (!matched) {\n return null;\n }\n\n const unit = DurationAliases.resolve(matched[2]);\n const value = Number(matched[1]);\n\n if (!unit || !Number.isFinite(value)) {\n return null;\n }\n\n return { unit, value };\n }\n\n /** `'30d'` straight to milliseconds - the shape a TTL or a grace period is usually configured in. */\n static parseToMilliseconds(input: string): number | null {\n return this.toMilliseconds(this.parse(input));\n }\n}\n"]}
1
+ {"version":3,"file":"duration.js","sourceRoot":"","sources":["../../../../src/common/constants/duration.ts"],"names":[],"mappings":";;;AAEA,qEAAqE;AACrE,MAAa,aAAa;aACR,gBAAW,GAAG,aAAa,CAAC;aAC5B,WAAM,GAAG,QAAQ,CAAC;aAClB,WAAM,GAAG,QAAQ,CAAC;aAClB,SAAI,GAAG,MAAM,CAAC;aACd,QAAG,GAAG,KAAK,CAAC;aACZ,SAAI,GAAG,MAAM,CAAC;aACd,UAAK,GAAG,OAAO,CAAC;aAChB,SAAI,GAAG,MAAM,CAAC;aAEd,eAAU,GAAG,IAAI,GAAG,CAAC;QACnC,IAAI,CAAC,WAAW;QAChB,IAAI,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G,MAAM,CAAC;IACxC,CAAC;IAED,2JAA2J;IAC3J,MAAM,CAAC,KAAK,CAAC,KAAa;QACxB,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;YAC9B,OAAO,IAAI,CAAC;QACd,CAAC;QAED,MAAM,OAAO,GAAG,gBAAgB,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC,CAAC;QAEpD,IAAI,CAAC,OAAO,EAAE,CAAC;YACb,OAAO,IAAI,CAAC;QACd,CAAC;QAED,MAAM,IAAI,GAAG,eAAe,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC;QACjD,MAAM,KAAK,GAAG,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC;QAEjC,IAAI,CAAC,IAAI,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC;YACrC,OAAO,IAAI,CAAC;QACd,CAAC;QAED,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC;IACzB,CAAC;IAED,qGAAqG;IACrG,MAAM,CAAC,mBAAmB,CAAC,KAAa;QACtC,OAAO,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC;IAChD,CAAC;;AA/FH,kDAgGC","sourcesContent":["import { type TConstValue } from '../types';\n\n/** The time units a duration can be expressed in, smallest first. */\nexport class DurationUnits {\n static readonly MILLISECOND = 'millisecond';\n static readonly SECOND = 'second';\n static readonly MINUTE = 'minute';\n static readonly HOUR = 'hour';\n static readonly DAY = 'day';\n static readonly WEEK = 'week';\n static readonly MONTH = 'month';\n static readonly YEAR = 'year';\n\n static readonly SCHEME_SET = new Set([\n this.MILLISECOND,\n this.SECOND,\n this.MINUTE,\n this.HOUR,\n this.DAY,\n this.WEEK,\n this.MONTH,\n this.YEAR,\n ]);\n\n static isValid(input: string): input is TDurationUnit {\n return this.SCHEME_SET.has(input);\n }\n}\n\nexport type TDurationUnit = TConstValue<typeof DurationUnits>;\n\n/**\n * Written spellings that resolve to a unit. Member names are the spelling, upper-cased - so\n * {@link resolve} upper-cases its input and reads one property, with no second table to keep in step.\n *\n * `M` is MINUTE and `MO` is MONTH - the same choice every duration library makes, and the one\n * ambiguity a reader will trip on. There is no single-letter month.\n */\nexport class DurationAliases {\n static readonly MS = DurationUnits.MILLISECOND;\n static readonly MSEC = DurationUnits.MILLISECOND;\n static readonly MILLISECOND = DurationUnits.MILLISECOND;\n static readonly MILLISECONDS = DurationUnits.MILLISECOND;\n\n static readonly S = DurationUnits.SECOND;\n static readonly SEC = DurationUnits.SECOND;\n static readonly SECOND = DurationUnits.SECOND;\n static readonly SECONDS = DurationUnits.SECOND;\n\n static readonly M = DurationUnits.MINUTE;\n static readonly MIN = DurationUnits.MINUTE;\n static readonly MINUTE = DurationUnits.MINUTE;\n static readonly MINUTES = DurationUnits.MINUTE;\n\n static readonly H = DurationUnits.HOUR;\n static readonly HR = DurationUnits.HOUR;\n static readonly HOUR = DurationUnits.HOUR;\n static readonly HOURS = DurationUnits.HOUR;\n\n static readonly D = DurationUnits.DAY;\n static readonly DAY = DurationUnits.DAY;\n static readonly DAYS = DurationUnits.DAY;\n\n static readonly W = DurationUnits.WEEK;\n static readonly WK = DurationUnits.WEEK;\n static readonly WEEK = DurationUnits.WEEK;\n static readonly WEEKS = DurationUnits.WEEK;\n\n static readonly MO = DurationUnits.MONTH;\n static readonly MON = DurationUnits.MONTH;\n static readonly MONTH = DurationUnits.MONTH;\n static readonly MONTHS = DurationUnits.MONTH;\n\n static readonly Y = DurationUnits.YEAR;\n static readonly YR = DurationUnits.YEAR;\n static readonly YEAR = DurationUnits.YEAR;\n static readonly YEARS = DurationUnits.YEAR;\n\n /** Resolves a written unit - `'d'`, `'days'`, `'DAY'` - to its canonical name, or `null`. */\n static resolve(input: string): TDurationUnit | null {\n if (typeof input !== 'string') {\n return null;\n }\n\n // Try the input as given first. `trim().toUpperCase()` allocates two strings and costs ~55ns,\n // where the lookup itself is ~1ns - so the spellings callers actually pass (`'day'`, `'d'`,\n // `'DAYS'`) must not pay for it. Measured, both ways.\n //\n // The table is declared below because it is derived FROM this class; it is read at call time,\n // never at class-evaluation time.\n /* eslint-disable @typescript-eslint/no-use-before-define */\n return ALIAS_LOOKUP.get(input) ?? ALIAS_LOOKUP.get(input.trim().toUpperCase()) ?? null;\n /* eslint-enable @typescript-eslint/no-use-before-define */\n }\n}\n\n/**\n * Derived from the class once, never hand-listed, so the two cannot drift. Reading the class\n * directly is slower and would need `name`/`length`/`constructor` guarded out. Each spelling is\n * stored upper and lower so the common call allocates nothing.\n */\nconst ALIAS_LOOKUP: Map<string, TDurationUnit> = new Map(\n Object.entries(DurationAliases)\n .filter((entry): entry is [string, TDurationUnit] => DurationUnits.isValid(entry[1] as string))\n .flatMap(([spelling, unit]): Array<[string, TDurationUnit]> => [\n [spelling, unit],\n [spelling.toLowerCase(), unit],\n ]),\n);\n\nexport interface IDuration {\n unit: TDurationUnit;\n value: number;\n}\n\n/** `30d`, `1500 ms`, `-2 Hours`. One number, optional space, one unit. */\nconst DURATION_PATTERN = /^([+-]?\\d+(?:\\.\\d+)?)\\s*([a-z]+)$/i;\n\n/**\n * A month is 30 days and a year 365, nominal. These size a WINDOW - a grace period, a cache TTL, a\n * near-expiry horizon - and must never compute a calendar date: adding `MONTH` to 31 January lands\n * on 2 March in a leap year and 3 March otherwise. Use a date library for calendar arithmetic.\n */\nexport class DurationMultipliers {\n static readonly MILLISECOND = 1;\n static readonly SECOND = 1000 * this.MILLISECOND;\n static readonly MINUTE = 60 * this.SECOND;\n static readonly HOUR = 60 * this.MINUTE;\n static readonly DAY = 24 * this.HOUR;\n static readonly WEEK = 7 * this.DAY;\n static readonly MONTH = 30 * this.DAY;\n static readonly YEAR = 365 * this.DAY;\n\n static readonly BY_UNIT: Record<string, number> = {\n [DurationUnits.MILLISECOND]: this.MILLISECOND,\n [DurationUnits.SECOND]: this.SECOND,\n [DurationUnits.MINUTE]: this.MINUTE,\n [DurationUnits.HOUR]: this.HOUR,\n [DurationUnits.DAY]: this.DAY,\n [DurationUnits.WEEK]: this.WEEK,\n [DurationUnits.MONTH]: this.MONTH,\n [DurationUnits.YEAR]: this.YEAR,\n };\n\n /** The multiplier of a known unit, `null` for anything else - inherited property names included. */\n private static multiplierOf(unit: unknown): number | null {\n return typeof unit === 'string' && DurationUnits.isValid(unit) ? this.BY_UNIT[unit] : null;\n }\n\n /**\n * `null` rather than a throw, so a caller that wants an error raises its own with its own context.\n * Every method here answers the same way.\n *\n * The unit is checked against {@link DurationUnits.SCHEME_SET} first: a plain-object read alone\n * would answer `'constructor'` or `'toString'` with a member of `Object.prototype`, not `undefined`.\n */\n static toMilliseconds(opts: IDuration | null): number | null {\n if (!opts) {\n return null;\n }\n\n const multiplier = this.multiplierOf(opts.unit);\n\n if (multiplier === null || !Number.isFinite(opts.value)) {\n return null;\n }\n\n return Math.round(opts.value * multiplier);\n }\n\n /** The inverse of {@link toMilliseconds}. Fractional on purpose - rounding here would silently lose a 36-hour window asked for in days. */\n static fromMilliseconds(opts: { milliseconds: number; unit: TDurationUnit }): number | null {\n const multiplier = this.multiplierOf(opts?.unit);\n\n if (multiplier === null || !Number.isFinite(opts.milliseconds)) {\n return null;\n }\n\n return opts.milliseconds / multiplier;\n }\n\n /** Unit to unit, through milliseconds. Fractional, for the reason {@link fromMilliseconds} gives. */\n static convert(opts: { value: number; from: TDurationUnit; to: TDurationUnit }): number | null {\n const source = this.multiplierOf(opts?.from);\n const target = this.multiplierOf(opts?.to);\n\n if (source === null || target === null || !Number.isFinite(opts.value)) {\n return null;\n }\n\n return (opts.value * source) / target;\n }\n\n /** Reads a written duration - `'30d'`, `'1500 ms'`, `'2 hours'` - into {@link IDuration}. Aliases and the `M`/`MO` rule are on {@link DurationAliases}. */\n static parse(input: string): IDuration | null {\n if (typeof input !== 'string') {\n return null;\n }\n\n const matched = DURATION_PATTERN.exec(input.trim());\n\n if (!matched) {\n return null;\n }\n\n const unit = DurationAliases.resolve(matched[2]);\n const value = Number(matched[1]);\n\n if (!unit || !Number.isFinite(value)) {\n return null;\n }\n\n return { unit, value };\n }\n\n /** `'30d'` straight to milliseconds - the shape a TTL or a grace period is usually configured in. */\n static parseToMilliseconds(input: string): number | null {\n return this.toMilliseconds(this.parse(input));\n }\n}\n"]}
@@ -94,7 +94,7 @@ const deepSanitize = (value, context) => {
94
94
  return result;
95
95
  }
96
96
  if (Array.isArray(value)) {
97
- return value.map(entry => deepSanitize(entry, nested));
97
+ return value.map((entry) => deepSanitize(entry, nested));
98
98
  }
99
99
  const source = value;
100
100
  const result = {};
@@ -1 +1 @@
1
- {"version":3,"file":"redact.js","sourceRoot":"","sources":["../../../src/common/redact.ts"],"names":[],"mappings":";;;AAEA,gHAAgH;AAChH,MAAM,kBAAkB,GAAG,IAAI,MAAM,CACnC;IACE,qDAAqD;IACrD,6EAA6E;IAC7E,0EAA0E;IAC1E,oEAAoE;IAEpE,iKAAiK;IACjK,qCAAqC;IAErC,8MAA8M;IAC9M,yBAAyB;IAEzB,8RAA8R;IAC9R,2BAA2B;IAE3B,4JAA4J;IAC5J,qDAAqD;IAErD,yIAAyI;IACzI,+BAA+B;IAE/B,2MAA2M;IAC3M,gFAAgF;IAChF,6DAA6D;CAC9D,CAAC,IAAI,CAAC,EAAE,CAAC,EACV,GAAG,CACJ,CAAC;AAEW,QAAA,QAAQ,GAAG,YAAY,CAAC;AAErC,8KAA8K;AAC9K,MAAM,kBAAkB,GAAG,GAAY,EAAE,CACvC,UAAU,CAAC,OAAO,EAAE,GAAG,EAAE,wBAAwB,KAAK,OAAO,CAAC;AAEhE,uGAAuG;AACvG,MAAM,yBAAyB,GAAG,IAAI,CAAC;AAEvC,MAAM,sBAAsB,GAAG,GAAW,EAAE;IAC1C,MAAM,UAAU,GAAG,MAAM,CAAC,UAAU,CAAC,OAAO,EAAE,GAAG,EAAE,gCAAgC,CAAC,CAAC;IACrF,OAAO,MAAM,CAAC,QAAQ,CA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;QACjG,qDAAqD;QACrD,eAAe,EAAE,sBAAsB,EAAE;KAC1C,CAAC,CAAC;AACL,CAAC,CAAC;AATW,QAAA,UAAU,cASrB;AAEF,sPAAsP;AAC/O,MAAM,oBAAoB,GAAG,CAAC,GAAW,EAAU,EAAE;IAC1D,IAAI,CAAC,kBAAkB,EAAE,EAAE,CAAC;QAC1B,OAAO,GAAG,CAAC;IACb,CAAC;IAED,IAAI,MAAW,CAAC;IAEhB,IAAI,CAAC;QACH,MAAM,GAAG,IAAI,GAAG,CAAC,GAAG,CAAC,CAAC;IACxB,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,GAAG,CAAC;IACb,CAAC;IAED,IAAI,CAAC,MAAM,CAAC,QAAQ,EAAE,CAAC;QACrB,OAAO,GAAG,CAAC;IACb,CAAC;IAED,MAAM,CAAC,QAAQ,GAAG,gBAAQ,CAAC;IAC3B,OAAO,kBAAkB,CAAC,MAAM,CAAC,QAAQ,EAAE,CAAC,CAAC;AAC/C,CAAC,CAAC;AAnBW,QAAA,oBAAoB,wBAmB/B","sourcesContent":["import { type AnyObject } from './types';\n\n/** Keys whose VALUES must never reach a log line - matched case-insensitively on the key name, at any depth. */\nconst SECRET_KEY_PATTERN = new RegExp(\n [\n // Options-object spellings (camelCase / snake_case).\n '^(pass|password|passphrase|secret|token|apiKey|api_key|accessKey|access_key',\n '|secretKey|secret_key|privateKey|private_key|key|cert|ca|pfx|credentials',\n '|authorization|auth|jwtSecret|applicationSecret|connectionString)$',\n\n // Vault wire spellings (snake_case): node-vault's AppRole login/response bodies carry these exact keys, and none are matched by the anchored options list above.\n '|^(client_token|secret_id|role_id)$',\n\n // Any `*_token` (snake_case) or `*Token` (camelCase) key; a preceding character is required so the bare word `token` (already covered above) is not the whole match, and so ordinary words are not swallowed.\n '|_token$|[a-z0-9]token$',\n\n // The `*Secret` counterpart the `*Token` rule always lacked. `clientSecret` / `client_secret` is the RFC 6749 parameter name and a live field on the search connector's model options, and `webhookSecret` is the standard spelling everywhere; none of them matched the anchored list above.\n '|_secret$|[a-z0-9]secret$',\n\n // Connection descriptors: `connectionString` was anchored above but its snake_case twin was not, and `dsn` is the third common spelling for the same thing.\n '|^(connection_string|dsn|database_url|databaseUrl)$',\n\n // Any `*_password` / `*Password` key - `dbPassword`, `admin_password`. The bare word is anchored above; this catches the prefixed forms.\n '|_password$|[a-z0-9]password$',\n\n // HTTP HEADER spellings: header names are kebab-case and often `x-`-prefixed, none of which the camelCase list above matches; `vault` is included so `X-Vault-Token` (node-vault's auth header) is caught.\n '|^(x-)?(api|auth|access|secret|session|csrf|xsrf|vault)-(key|token|secret|id)$',\n '|^(cookie|set-cookie|proxy-authorization|www-authenticate)$',\n ].join(''),\n 'i',\n);\n\nexport const REDACTED = '[REDACTED]';\n\n/** Kill-switch for local debugging: only the literal `false` disables redaction (fail-closed); read per call so it can be flipped at runtime. Never disable in production. */\nconst isRedactionEnabled = (): boolean =>\n globalThis.process?.env?.APP_ENV_LOGGER_DO_REDACT !== 'false';\n\n/** Longest string a log line carries whole. `APP_ENV_LOGGER_MAX_STRING_LENGTH=0` turns capping off. */\nconst DEFAULT_MAX_STRING_LENGTH = 2048;\n\nconst resolveMaxStringLength = (): number => {\n const configured = Number(globalThis.process?.env?.APP_ENV_LOGGER_MAX_STRING_LENGTH);\n return Number.isFinite(configured) && configured >= 0 ? configured : DEFAULT_MAX_STRING_LENGTH;\n};\n\n/**\n * Keys whose value is long BY NATURE and useless truncated. A stack trace is the whole reason you\n * are reading the line.\n */\nconst UNCAPPED_KEYS = new Set(['stack', 'stacktrace', 'stack_trace']);\n\n/**\n * Caps a long string, keeping the ORIGINAL LENGTH in the marker - that number is what tells you the\n * payload was a 300 KB image rather than a truncated sentence.\n *\n * A base64 body is the case this exists for: one `data:image/png;base64,...` field turns a request\n * log into hundreds of kilobytes, and nothing about it is readable.\n */\nconst capString = (opts: { value: string; key?: string; limit: number }): string => {\n const { value, key, limit } = opts;\n\n if (limit === 0 || value.length <= limit || (key && UNCAPPED_KEYS.has(key.toLowerCase()))) {\n return value;\n }\n\n return `${value.slice(0, limit)}... [truncated, ${value.length} chars total]`;\n};\n\ntype TSanitizeContext = {\n seen: WeakSet<object>;\n doRedact: boolean;\n /** Levels still allowed BELOW the current one; `Infinity` walks the whole graph. */\n depth: number;\n /** Longest string kept whole; 0 keeps every string. */\n maxStringLength: number;\n /** The key this value was found under, so a stack trace can be exempted from capping. */\n key?: string;\n};\n\nconst deepSanitize = (value: unknown, context: TSanitizeContext): unknown => {\n const { seen, doRedact, depth } = context;\n\n if (typeof value === 'string') {\n return capString({ value, key: context.key, limit: context.maxStringLength });\n }\n\n if (value === null || typeof value !== 'object') {\n return value;\n }\n\n // A Date holds its value in an internal slot, so the generic branch below - which reads Object.keys() - would flatten it to `{}`. Checked BEFORE `seen`: a Date cannot carry a cycle, and entering the set would make a second reference to the same instance read as `[Circular]`.\n if (value instanceof Date) {\n return value;\n }\n\n if (seen.has(value)) {\n return '[Circular]';\n }\n\n if (ArrayBuffer.isView(value) || value instanceof ArrayBuffer) {\n return `[Binary ${(value as ArrayBufferView).byteLength ?? 0} bytes]`;\n }\n\n if (depth <= 0) {\n return Array.isArray(value) ? '[Array]' : '[Object]';\n }\n\n seen.add(value);\n const nested: TSanitizeContext = {\n seen,\n doRedact,\n depth: depth - 1,\n maxStringLength: context.maxStringLength,\n };\n\n // Error keeps name/message/stack NON-enumerable, so Object.keys() skips them and naive redaction would drop the message - reproject into a plain object carrying those fields plus its redacted enumerable own-props.\n if (value instanceof Error) {\n const source = value;\n const result: AnyObject = {\n name: value.name,\n message: value.message,\n stack: value.stack,\n };\n\n for (const [key, entry] of Object.entries(source)) {\n result[key] =\n doRedact && SECRET_KEY_PATTERN.test(key)\n ? REDACTED\n : deepSanitize(entry, { ...nested, key });\n }\n\n return result;\n }\n\n if (Array.isArray(value)) {\n return value.map(entry => deepSanitize(entry, nested));\n }\n\n const source = value;\n const result: AnyObject = {};\n\n for (const [key, entry] of Object.entries(source)) {\n if (doRedact && SECRET_KEY_PATTERN.test(key)) {\n result[key] = REDACTED;\n continue;\n }\n\n result[key] = deepSanitize(entry, { ...nested, key });\n }\n\n return result;\n};\n\n/**\n * Redacts every secret-looking KEY (not value shape - buffers/typed arrays are summarized, not\n * serialized). `APP_ENV_LOGGER_DO_REDACT=false` makes this the identity function.\n *\n * `depth` bounds the walk, exactly as {@link toJsonSafe} already does. It defaults to `Infinity` for\n * callers that really do want the whole graph, but the logger passes its own bound: rendering only\n * inspects a handful of levels, so walking to `Infinity` did work whose result was thrown away -\n * 12x on a deep graph, and a `RangeError` on a very deep chain.\n */\nexport const redactSecrets = (\n value: unknown,\n seen?: WeakSet<object>,\n depth: number = Infinity,\n): unknown => {\n if (!isRedactionEnabled()) {\n return value;\n }\n\n return deepSanitize(value, {\n seen: seen ?? new WeakSet<object>(),\n doRedact: true,\n depth,\n maxStringLength: resolveMaxStringLength(),\n });\n};\n\n/** Projects a value into something `JSON.stringify` can render: it answers `[Circular]` for the WHOLE payload when one cycle sits anywhere inside it, so cycles must be broken per-branch first. `depth` bounds the walk the way `util.inspect` does - a log argument may hold a live connector or request context, whose graph is effectively unbounded. The projection itself is unconditional: `APP_ENV_LOGGER_DO_REDACT=false` turns off the key masking, never the structural pass. */\nexport const toJsonSafe = (opts: { value: unknown; depth?: number }): unknown => {\n return deepSanitize(opts.value, {\n seen: new WeakSet<object>(),\n doRedact: isRedactionEnabled(),\n depth: opts.depth ?? Infinity,\n // Capping is STRUCTURAL, like the projection itself: turning redaction off is about key masking,\n // never about letting a 300 KB base64 field through.\n maxStringLength: resolveMaxStringLength(),\n });\n};\n\n/** Strips credentials from a connection URL's authority section (`user:hunter2@host` -> `user:[REDACTED]@host`) - {@link redactSecrets} matches on KEY names and can't see them there. A value that fails to parse as a URL is returned unchanged. */\nexport const redactUrlCredentials = (url: string): string => {\n if (!isRedactionEnabled()) {\n return url;\n }\n\n let parsed: URL;\n\n try {\n parsed = new URL(url);\n } catch {\n return url;\n }\n\n if (!parsed.password) {\n return url;\n }\n\n parsed.password = REDACTED;\n return decodeURIComponent(parsed.toString());\n};\n"]}
1
+ {"version":3,"file":"redact.js","sourceRoot":"","sources":["../../../src/common/redact.ts"],"names":[],"mappings":";;;AAEA,gHAAgH;AAChH,MAAM,kBAAkB,GAAG,IAAI,MAAM,CACnC;IACE,qDAAqD;IACrD,6EAA6E;IAC7E,0EAA0E;IAC1E,oEAAoE;IAEpE,iKAAiK;IACjK,qCAAqC;IAErC,8MAA8M;IAC9M,yBAAyB;IAEzB,8RAA8R;IAC9R,2BAA2B;IAE3B,4JAA4J;IAC5J,qDAAqD;IAErD,yIAAyI;IACzI,+BAA+B;IAE/B,2MAA2M;IAC3M,gFAAgF;IAChF,6DAA6D;CAC9D,CAAC,IAAI,CAAC,EAAE,CAAC,EACV,GAAG,CACJ,CAAC;AAEW,QAAA,QAAQ,GAAG,YAAY,CAAC;AAErC,8KAA8K;AAC9K,MAAM,kBAAkB,GAAG,GAAY,EAAE,CACvC,UAAU,CAAC,OAAO,EAAE,GAAG,EAAE,wBAAwB,KAAK,OAAO,CAAC;AAEhE,uGAAuG;AACvG,MAAM,yBAAyB,GAAG,IAAI,CAAC;AAEvC,MAAM,sBAAsB,GAAG,GAAW,EAAE;IAC1C,MAAM,UAAU,GAAG,MAAM,CAAC,UAAU,CAAC,OAAO,EAAE,GAAG,EAAE,gCAAgC,CAAC,CAAC;IACrF,OAAO,MAAM,CAAC,QAAQ,CAAC,UAAU,CAAC,IAAI,UAAU,IAAI,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,yBAAyB,CAAC;AACjG,CAAC,CAAC;AAEF;;;GAGG;AACH,MAAM,aAAa,GAAG,IAAI,GAAG,CAAC,CAAC,OAAO,EAAE,YAAY,EAAE,aAAa,CAAC,CAAC,CAAC;AAEtE;;;;;;GAMG;AACH,MAAM,SAAS,GAAG,CAAC,IAAoD,EAAU,EAAE;IACjF,MAAM,EAAE,KAAK,EAAE,GAAG,EAAE,KAAK,E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AAG,CAAC,CAAC;IACxB,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,GAAG,CAAC;IACb,CAAC;IAED,IAAI,CAAC,MAAM,CAAC,QAAQ,EAAE,CAAC;QACrB,OAAO,GAAG,CAAC;IACb,CAAC;IAED,MAAM,CAAC,QAAQ,GAAG,gBAAQ,CAAC;IAC3B,OAAO,kBAAkB,CAAC,MAAM,CAAC,QAAQ,EAAE,CAAC,CAAC;AAC/C,CAAC,CAAC;AAnBW,QAAA,oBAAoB,wBAmB/B","sourcesContent":["import { type AnyObject } from './types';\n\n/** Keys whose VALUES must never reach a log line - matched case-insensitively on the key name, at any depth. */\nconst SECRET_KEY_PATTERN = new RegExp(\n [\n // Options-object spellings (camelCase / snake_case).\n '^(pass|password|passphrase|secret|token|apiKey|api_key|accessKey|access_key',\n '|secretKey|secret_key|privateKey|private_key|key|cert|ca|pfx|credentials',\n '|authorization|auth|jwtSecret|applicationSecret|connectionString)$',\n\n // Vault wire spellings (snake_case): node-vault's AppRole login/response bodies carry these exact keys, and none are matched by the anchored options list above.\n '|^(client_token|secret_id|role_id)$',\n\n // Any `*_token` (snake_case) or `*Token` (camelCase) key; a preceding character is required so the bare word `token` (already covered above) is not the whole match, and so ordinary words are not swallowed.\n '|_token$|[a-z0-9]token$',\n\n // The `*Secret` counterpart the `*Token` rule always lacked. `clientSecret` / `client_secret` is the RFC 6749 parameter name and a live field on the search connector's model options, and `webhookSecret` is the standard spelling everywhere; none of them matched the anchored list above.\n '|_secret$|[a-z0-9]secret$',\n\n // Connection descriptors: `connectionString` was anchored above but its snake_case twin was not, and `dsn` is the third common spelling for the same thing.\n '|^(connection_string|dsn|database_url|databaseUrl)$',\n\n // Any `*_password` / `*Password` key - `dbPassword`, `admin_password`. The bare word is anchored above; this catches the prefixed forms.\n '|_password$|[a-z0-9]password$',\n\n // HTTP HEADER spellings: header names are kebab-case and often `x-`-prefixed, none of which the camelCase list above matches; `vault` is included so `X-Vault-Token` (node-vault's auth header) is caught.\n '|^(x-)?(api|auth|access|secret|session|csrf|xsrf|vault)-(key|token|secret|id)$',\n '|^(cookie|set-cookie|proxy-authorization|www-authenticate)$',\n ].join(''),\n 'i',\n);\n\nexport const REDACTED = '[REDACTED]';\n\n/** Kill-switch for local debugging: only the literal `false` disables redaction (fail-closed); read per call so it can be flipped at runtime. Never disable in production. */\nconst isRedactionEnabled = (): boolean =>\n globalThis.process?.env?.APP_ENV_LOGGER_DO_REDACT !== 'false';\n\n/** Longest string a log line carries whole. `APP_ENV_LOGGER_MAX_STRING_LENGTH=0` turns capping off. */\nconst DEFAULT_MAX_STRING_LENGTH = 2048;\n\nconst resolveMaxStringLength = (): number => {\n const configured = Number(globalThis.process?.env?.APP_ENV_LOGGER_MAX_STRING_LENGTH);\n return Number.isFinite(configured) && configured >= 0 ? configured : DEFAULT_MAX_STRING_LENGTH;\n};\n\n/**\n * Keys whose value is long BY NATURE and useless truncated. A stack trace is the whole reason you\n * are reading the line.\n */\nconst UNCAPPED_KEYS = new Set(['stack', 'stacktrace', 'stack_trace']);\n\n/**\n * Caps a long string, keeping the ORIGINAL LENGTH in the marker - that number is what tells you the\n * payload was a 300 KB image rather than a truncated sentence.\n *\n * A base64 body is the case this exists for: one `data:image/png;base64,...` field turns a request\n * log into hundreds of kilobytes, and nothing about it is readable.\n */\nconst capString = (opts: { value: string; key?: string; limit: number }): string => {\n const { value, key, limit } = opts;\n\n if (limit === 0 || value.length <= limit || (key && UNCAPPED_KEYS.has(key.toLowerCase()))) {\n return value;\n }\n\n return `${value.slice(0, limit)}... [truncated, ${value.length} chars total]`;\n};\n\ntype TSanitizeContext = {\n seen: WeakSet<object>;\n doRedact: boolean;\n /** Levels still allowed BELOW the current one; `Infinity` walks the whole graph. */\n depth: number;\n /** Longest string kept whole; 0 keeps every string. */\n maxStringLength: number;\n /** The key this value was found under, so a stack trace can be exempted from capping. */\n key?: string;\n};\n\nconst deepSanitize = (value: unknown, context: TSanitizeContext): unknown => {\n const { seen, doRedact, depth } = context;\n\n if (typeof value === 'string') {\n return capString({ value, key: context.key, limit: context.maxStringLength });\n }\n\n if (value === null || typeof value !== 'object') {\n return value;\n }\n\n // A Date holds its value in an internal slot, so the generic branch below - which reads Object.keys() - would flatten it to `{}`. Checked BEFORE `seen`: a Date cannot carry a cycle, and entering the set would make a second reference to the same instance read as `[Circular]`.\n if (value instanceof Date) {\n return value;\n }\n\n if (seen.has(value)) {\n return '[Circular]';\n }\n\n if (ArrayBuffer.isView(value) || value instanceof ArrayBuffer) {\n return `[Binary ${(value as ArrayBufferView).byteLength ?? 0} bytes]`;\n }\n\n if (depth <= 0) {\n return Array.isArray(value) ? '[Array]' : '[Object]';\n }\n\n seen.add(value);\n const nested: TSanitizeContext = {\n seen,\n doRedact,\n depth: depth - 1,\n maxStringLength: context.maxStringLength,\n };\n\n // Error keeps name/message/stack NON-enumerable, so Object.keys() skips them and naive redaction would drop the message - reproject into a plain object carrying those fields plus its redacted enumerable own-props.\n if (value instanceof Error) {\n const source = value;\n const result: AnyObject = {\n name: value.name,\n message: value.message,\n stack: value.stack,\n };\n\n for (const [key, entry] of Object.entries(source)) {\n result[key] =\n doRedact && SECRET_KEY_PATTERN.test(key)\n ? REDACTED\n : deepSanitize(entry, { ...nested, key });\n }\n\n return result;\n }\n\n if (Array.isArray(value)) {\n return value.map((entry) => deepSanitize(entry, nested));\n }\n\n const source = value;\n const result: AnyObject = {};\n\n for (const [key, entry] of Object.entries(source)) {\n if (doRedact && SECRET_KEY_PATTERN.test(key)) {\n result[key] = REDACTED;\n continue;\n }\n\n result[key] = deepSanitize(entry, { ...nested, key });\n }\n\n return result;\n};\n\n/**\n * Redacts every secret-looking KEY (not value shape - buffers/typed arrays are summarized, not\n * serialized). `APP_ENV_LOGGER_DO_REDACT=false` makes this the identity function.\n *\n * `depth` bounds the walk, exactly as {@link toJsonSafe} already does. It defaults to `Infinity` for\n * callers that really do want the whole graph, but the logger passes its own bound: rendering only\n * inspects a handful of levels, so walking to `Infinity` did work whose result was thrown away -\n * 12x on a deep graph, and a `RangeError` on a very deep chain.\n */\nexport const redactSecrets = (\n value: unknown,\n seen?: WeakSet<object>,\n depth: number = Infinity,\n): unknown => {\n if (!isRedactionEnabled()) {\n return value;\n }\n\n return deepSanitize(value, {\n seen: seen ?? new WeakSet<object>(),\n doRedact: true,\n depth,\n maxStringLength: resolveMaxStringLength(),\n });\n};\n\n/** Projects a value into something `JSON.stringify` can render: it answers `[Circular]` for the WHOLE payload when one cycle sits anywhere inside it, so cycles must be broken per-branch first. `depth` bounds the walk the way `util.inspect` does - a log argument may hold a live connector or request context, whose graph is effectively unbounded. The projection itself is unconditional: `APP_ENV_LOGGER_DO_REDACT=false` turns off the key masking, never the structural pass. */\nexport const toJsonSafe = (opts: { value: unknown; depth?: number }): unknown => {\n return deepSanitize(opts.value, {\n seen: new WeakSet<object>(),\n doRedact: isRedactionEnabled(),\n depth: opts.depth ?? Infinity,\n // Capping is STRUCTURAL, like the projection itself: turning redaction off is about key masking,\n // never about letting a 300 KB base64 field through.\n maxStringLength: resolveMaxStringLength(),\n });\n};\n\n/** Strips credentials from a connection URL's authority section (`user:hunter2@host` -> `user:[REDACTED]@host`) - {@link redactSecrets} matches on KEY names and can't see them there. A value that fails to parse as a URL is returned unchanged. */\nexport const redactUrlCredentials = (url: string): string => {\n if (!isRedactionEnabled()) {\n return url;\n }\n\n let parsed: URL;\n\n try {\n parsed = new URL(url);\n } catch {\n return url;\n }\n\n if (!parsed.password) {\n return url;\n }\n\n parsed.password = REDACTED;\n return decodeURIComponent(parsed.toString());\n};\n"]}
@@ -9,7 +9,7 @@ class BaseHelper {
9
9
  }
10
10
  /** The helper's logger, resolved on first read - a helper that never logs never builds one. */
11
11
  get logger() {
12
- const scopes = [this.scope, this.identifier].filter(scope => typeof scope === 'string' && scope.length > 0);
12
+ const scopes = [this.scope, this.identifier].filter((scope) => typeof scope === 'string' && scope.length > 0);
13
13
  const logger = (0, slot_1.resolveHelperLogger)({ scopes });
14
14
  // Read off a prototype (reflection walks them), pinning would shadow this getter for every instance.
15
15
  if (Object.hasOwn(this, 'scope')) {
@@ -1 +1 @@
1
- {"version":3,"file":"base.js","sourceRoot":"","sources":["../../../src/modules/base.ts"],"names":[],"mappings":";;;AACA,gDAA6E;AAE7E,MAAa,UAAU;IAIrB,YAAY,IAA4C;QACtD,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK,IAAI,EAAE,CAAC;QAC9B,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,UAAU,IAAI,EAAE,CAAC;IAC1C,CAAC;IAED,+FAA+F;IAC/F,IAAI,MAAM;QACR,MAAM,MAAM,GAAG,CAAC,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC,MAAM,CACjD,KAAK,CAAC,EAAE,CAAC,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC,CACvD,CAAC;QACF,MAAM,MAAM,GAAG,IAAA,0BAAmB,EAAC,EAAE,MAAM,EAAE,CAAC,CAAC;QAE/C,qGAAqG;QACrG,IAAI,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,EAAE,CAAC;YACjC,IAAA,sBAAe,EAAC,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC,CAAC;QAC5C,CAAC;QACD,OAAO,MAAM,CAAC;IAChB,CAAC;IAED,iGAAiG;IACjG,IAAI,MAAM,CAAC,KAAc;QACvB,IAAA,sBAAe,EAAC,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,CAAC;IACnD,CAAC;IAED,aAAa;QACX,OAAO,IAAI,CAAC,UAAU,CAAC;IACzB,CAAC;IAED,SAAS;QACP,OAAO,IAAI,CAAC,MAAM,CAAC;IACrB,CAAC;CACF;AAnCD,gCAmCC","sourcesContent":["import { type ILogger } from '@/modules/logger/common/types';\nimport { pinHelperLogger, resolveHelperLogger } from '@/modules/logger/slot';\n\nexport class BaseHelper {\n scope: string;\n identifier: string;\n\n constructor(opts: { scope: string; identifier?: string }) {\n this.scope = opts.scope ?? '';\n this.identifier = opts.identifier ?? '';\n }\n\n /** The helper's logger, resolved on first read - a helper that never logs never builds one. */\n get logger(): ILogger {\n const scopes = [this.scope, this.identifier].filter(\n scope => typeof scope === 'string' && scope.length > 0,\n );\n const logger = resolveHelperLogger({ scopes });\n\n // Read off a prototype (reflection walks them), pinning would shadow this getter for every instance.\n if (Object.hasOwn(this, 'scope')) {\n pinHelperLogger({ helper: this, logger });\n }\n return logger;\n }\n\n /** Installs one logger on this helper - a test spy, or a host overriding the global resolver. */\n set logger(value: ILogger) {\n pinHelperLogger({ helper: this, logger: value });\n }\n\n getIdentifier() {\n return this.identifier;\n }\n\n getLogger(): ILogger {\n return this.logger;\n }\n}\n"]}
1
+ {"version":3,"file":"base.js","sourceRoot":"","sources":["../../../src/modules/base.ts"],"names":[],"mappings":";;;AACA,gDAA6E;AAE7E,MAAa,UAAU;IAIrB,YAAY,IAA4C;QACtD,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK,IAAI,EAAE,CAAC;QAC9B,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,UAAU,IAAI,EAAE,CAAC;IAC1C,CAAC;IAED,+FAA+F;IAC/F,IAAI,MAAM;QACR,MAAM,MAAM,GAAG,CAAC,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC,MAAM,CACjD,CAAC,KAAK,EAAE,EAAE,CAAC,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC,CACzD,CAAC;QACF,MAAM,MAAM,GAAG,IAAA,0BAAmB,EAAC,EAAE,MAAM,EAAE,CAAC,CAAC;QAE/C,qGAAqG;QACrG,IAAI,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,EAAE,CAAC;YACjC,IAAA,sBAAe,EAAC,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC,CAAC;QAC5C,CAAC;QACD,OAAO,MAAM,CAAC;IAChB,CAAC;IAED,iGAAiG;IACjG,IAAI,MAAM,CAAC,KAAc;QACvB,IAAA,sBAAe,EAAC,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,CAAC;IACnD,CAAC;IAED,aAAa;QACX,OAAO,IAAI,CAAC,UAAU,CAAC;IACzB,CAAC;IAED,SAAS;QACP,OAAO,IAAI,CAAC,MAAM,CAAC;IACrB,CAAC;CACF;AAnCD,gCAmCC","sourcesContent":["import { type ILogger } from '@/modules/logger/common/types';\nimport { pinHelperLogger, resolveHelperLogger } from '@/modules/logger/slot';\n\nexport class BaseHelper {\n scope: string;\n identifier: string;\n\n constructor(opts: { scope: string; identifier?: string }) {\n this.scope = opts.scope ?? '';\n this.identifier = opts.identifier ?? '';\n }\n\n /** The helper's logger, resolved on first read - a helper that never logs never builds one. */\n get logger(): ILogger {\n const scopes = [this.scope, this.identifier].filter(\n (scope) => typeof scope === 'string' && scope.length > 0,\n );\n const logger = resolveHelperLogger({ scopes });\n\n // Read off a prototype (reflection walks them), pinning would shadow this getter for every instance.\n if (Object.hasOwn(this, 'scope')) {\n pinHelperLogger({ helper: this, logger });\n }\n return logger;\n }\n\n /** Installs one logger on this helper - a test spy, or a host overriding the global resolver. */\n set logger(value: ILogger) {\n pinHelperLogger({ helper: this, logger: value });\n }\n\n getIdentifier() {\n return this.identifier;\n }\n\n getLogger(): ILogger {\n return this.logger;\n }\n}\n"]}
@@ -39,7 +39,7 @@ class AES extends base_algorithm_1.BaseCryptoAlgorithm {
39
39
  if (!Array.isArray(secret)) {
40
40
  return this.normalizeSecretKey({ secret, length, kdfSalt, kdfIterations });
41
41
  }
42
- const entry = secret.find(e => e.id === id);
42
+ const entry = secret.find((e) => e.id === id);
43
43
  if (!entry) {
44
44
  throw (0, error_1.getError)({
45
45
  message: `[AES][resolveDecryptKey] No key in keyring matches ciphertext key id "${id}"`,
@@ -1 +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AC;YACf,IAAI,OAAO,EAAE,CAAC;gBACZ,MAAM,KAAK,CAAC;YACd,CAAC;YAED,OAAO,OAAO,CAAC;QACjB,CAAC;IACH,CAAC;IAED,WAAW,CAAC,IAAkD;QAC5D,MAAM,EAAE,YAAY,EAAE,MAAM,EAAE,GAAG,IAAI,CAAC;QAEtC,IAAI,CAAC,YAAY,IAAI,IAAA,yBAAO,EAAC,EAAE,KAAK,EAAE,YAAY,EAAE,CAAC,EAAE,CAAC;YACtD,OAAO,EAAE,CAAC;QACZ,CAAC;QAED,MAAM,MAAM,GAAG,iBAAE,CAAC,YAAY,CAAC,YAAY,CAAC,CAAC;QAC7C,MAAM,WAAW,GAAG,MAAM,EAAE,QAAQ,CAAC,OAAO,CAAC,CAAC;QAC9C,MAAM,SAAS,GAAG,IAAI,CAAC,OAAO,CAAC,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,CAAC,CAAC;QACjE,OAAO,SAAS,CAAC;IACnB,CAAC;CACF;AArMD,kBAqMC","sourcesContent":["import { isEmpty } from '@venizia/ignis-inversion';\nimport C from 'node:crypto';\nimport fs from 'node:fs';\nimport { getError } from '@/modules/error';\nimport { BaseCryptoAlgorithm } from './base.algorithm';\n\nconst DEFAULT_LENGTH = 16;\nconst CIPHERTEXT_VERSION = 0x01;\nconst DEFAULT_KEY_ID = '0';\n\ninterface IAESDecryptOptions {\n inputEncoding?: BufferEncoding;\n outputEncoding?: BufferEncoding;\n doThrow?: boolean;\n /** Per-deployment PBKDF2 salt override. Must be supplied identically on encrypt and decrypt; omit for the shipped default. */\n kdfSalt?: string;\n /** PBKDF2 iteration count override. Must be supplied identically on encrypt and decrypt; omit for the shipped default. */\n kdfIterations?: number;\n}\n\n/** `iv` is encrypt-only: the envelope carries the IV, so decrypt reads it from there and a supplied one would be silently ignored. */\ninterface IAESExtraOptions extends IAESDecryptOptions {\n iv?: Buffer;\n}\n\nexport interface IAESKeyringEntry {\n id: string;\n secret: string;\n}\n\nexport type TAESSecret = string | IAESKeyringEntry[];\n\nexport type AESAlgorithmType = 'aes-256-cbc' | 'aes-256-gcm';\n\nexport class AES extends BaseCryptoAlgorithm<\n AESAlgorithmType,\n string,\n string,\n TAESSecret,\n string,\n string,\n IAESExtraOptions\n> {\n constructor(opts: { algorithm: AESAlgorithmType }) {\n super({ scope: AES.name, ...opts });\n }\n\n static withAlgorithm(algorithm: AESAlgorithmType) {\n return new AES({ algorithm });\n }\n\n protected resolveEncryptKey(opts: {\n secret: TAESSecret;\n kdfSalt?: string;\n kdfIterations?: number;\n }): { id: string; key: Buffer } {\n const { secret, kdfSalt, kdfIterations } = opts;\n const entry = Array.isArray(secret) ? secret[0] : { id: DEFAULT_KEY_ID, secret };\n\n if (!entry || isEmpty({ value: entry.secret })) {\n throw getError({ message: '[AES][resolveEncryptKey] Missing secret or empty keyring' });\n }\n\n const key = this.normalizeSecretKey({\n secret: entry.secret,\n length: this.getAlgorithmKeySize(),\n kdfSalt,\n kdfIterations,\n });\n return { id: entry.id, key };\n }\n\n protected resolveDecryptKey(opts: {\n secret: TAESSecret;\n id: string;\n kdfSalt?: string;\n kdfIterations?: number;\n }): Buffer {\n const { secret, id, kdfSalt, kdfIterations } = opts;\n const length = this.getAlgorithmKeySize();\n\n if (!Array.isArray(secret)) {\n return this.normalizeSecretKey({ secret, length, kdfSalt, kdfIterations });\n }\n\n const entry = secret.find(e => e.id === id);\n if (!entry) {\n throw getError({\n message: `[AES][resolveDecryptKey] No key in keyring matches ciphertext key id \"${id}\"`,\n });\n }\n\n // Without this the empty secret derives a key from '' and fails as an opaque OpenSSL error, hiding a plain configuration mistake.\n if (isEmpty({ value: entry.secret })) {\n throw getError({\n message: `[AES][resolveDecryptKey] Keyring entry for key id \"${id}\" has an empty secret`,\n });\n }\n\n return this.normalizeSecretKey({ secret: entry.secret, length, kdfSalt, kdfIterations });\n }\n\n encrypt(opts: { message: string; secret: TAESSecret; opts?: IAESExtraOptions }) {\n const { message, secret } = opts;\n const {\n iv = C.randomBytes(DEFAULT_LENGTH),\n inputEncoding = 'utf-8',\n outputEncoding = 'base64',\n doThrow = true,\n kdfSalt,\n kdfIterations,\n } = opts.opts ?? {};\n\n try {\n const { id, key } = this.resolveEncryptKey({ secret, kdfSalt, kdfIterations });\n const idBuffer = Buffer.from(id, 'utf-8');\n if (idBuffer.length > 0xff) {\n throw getError({ message: '[AES][encrypt] Key id too long (max 255 bytes)' });\n }\n\n const cipher = C.createCipheriv(this.algorithm, key, iv);\n\n // Envelope: [version(1)][idLen(1)][id(idLen)][iv(16)][authTag(16, gcm only)][cipher]\n const header = Buffer.from([CIPHERTEXT_VERSION, idBuffer.length]);\n const parts = [header, idBuffer, iv];\n\n const cipherText = cipher.update(message, inputEncoding);\n const cipherFinal = cipher.final();\n\n switch (this.algorithm) {\n case 'aes-256-cbc': {\n break;\n }\n case 'aes-256-gcm': {\n parts.push((cipher as C.CipherGCM).getAuthTag());\n break;\n }\n }\n parts.push(cipherText);\n parts.push(cipherFinal);\n\n return Buffer.concat(parts).toString(outputEncoding);\n } catch (error) {\n if (doThrow) {\n throw error;\n }\n\n return message;\n }\n }\n\n encryptFile(opts: { absolutePath: string; secret: TAESSecret }): string {\n const { absolutePath, secret } = opts;\n\n if (!absolutePath || isEmpty({ value: absolutePath })) {\n return '';\n }\n\n const buffer = fs.readFileSync(absolutePath);\n const fileContent = buffer?.toString('utf-8');\n const encrypted = this.encrypt({ message: fileContent, secret });\n return encrypted;\n }\n\n decrypt(opts: { message: string; secret: TAESSecret; opts?: IAESDecryptOptions }) {\n const { message, secret } = opts;\n const {\n inputEncoding = 'base64',\n outputEncoding = 'utf-8',\n doThrow = true,\n kdfSalt,\n kdfIterations,\n } = opts.opts ?? {};\n\n try {\n const raw = Buffer.from(message, inputEncoding);\n\n const version = raw[0];\n if (version !== CIPHERTEXT_VERSION) {\n throw getError({ message: `[AES][decrypt] Unsupported ciphertext version: ${version}` });\n }\n\n const idLength = raw[1];\n let cursor = 2;\n\n const id = raw.subarray(cursor, cursor + idLength).toString('utf-8');\n cursor += idLength;\n\n const iv = raw.subarray(cursor, cursor + DEFAULT_LENGTH);\n cursor += DEFAULT_LENGTH;\n\n const key = this.resolveDecryptKey({ secret, id, kdfSalt, kdfIterations });\n const decipher = C.createDecipheriv(this.algorithm, key, iv);\n\n switch (this.algorithm) {\n case 'aes-256-cbc': {\n break;\n }\n case 'aes-256-gcm': {\n const authTag = raw.subarray(cursor, cursor + DEFAULT_LENGTH);\n cursor += DEFAULT_LENGTH;\n (decipher as C.DecipherGCM).setAuthTag(authTag);\n break;\n }\n }\n\n const cipherText = raw.subarray(cursor);\n return Buffer.concat([decipher.update(cipherText), decipher.final()]).toString(\n outputEncoding,\n );\n } catch (error) {\n if (doThrow) {\n throw error;\n }\n\n return message;\n }\n }\n\n decryptFile(opts: { absolutePath: string; secret: TAESSecret }) {\n const { absolutePath, secret } = opts;\n\n if (!absolutePath || isEmpty({ value: absolutePath })) {\n return '';\n }\n\n const buffer = fs.readFileSync(absolutePath);\n const fileContent = buffer?.toString('utf-8');\n const decrypted = this.decrypt({ message: fileContent, secret });\n return decrypted;\n }\n}\n"]}
1
+ {"version":3,"file":"aes.algorithm.js","sourceRoot":"","sources":["../../../../../src/modules/crypto/algorithms/aes.algorithm.ts"],"names":[],"mappings":";;;;;;AAAA,8DAAmD;AACnD,8DAA4B;AAC5B,sDAAyB;AACzB,2CAA2C;AAC3C,qDAAuD;AAEvD,MAAM,cAAc,GAAG,EAAE,CAAC;AAC1B,MAAM,kBAAkB,GAAG,IAAI,CAAC;AAChC,MAAM,cAAc,GAAG,GAAG,CAAC;AA0B3B,MAAa,GAAI,SAAQ,oCAQxB;IACC,YAAY,IAAqC;QAC/C,KAAK,CAAC,EAAE,KAAK,EAAE,GAAG,CAAC,IAAI,EAAE,GAAG,IAAI,EAAE,CAAC,CAAC;IACtC,CAAC;IAED,MAAM,CAAC,aAAa,CAAC,SAA2B;QAC9C,OAAO,IAAI,GAAG,CAAC,EAAE,SAAS,EAAE,CAAC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,WAAW,EAAE,MAAM,EAAE,CAAC,CAAC;QACjE,OAAO,SAAS,CAAC;IACnB,CAAC;CACF;AArMD,kBAqMC","sourcesContent":["import { isEmpty } from '@venizia/ignis-inversion';\nimport C from 'node:crypto';\nimport fs from 'node:fs';\nimport { getError } from '@/modules/error';\nimport { BaseCryptoAlgorithm } from './base.algorithm';\n\nconst DEFAULT_LENGTH = 16;\nconst CIPHERTEXT_VERSION = 0x01;\nconst DEFAULT_KEY_ID = '0';\n\ninterface IAESDecryptOptions {\n inputEncoding?: BufferEncoding;\n outputEncoding?: BufferEncoding;\n doThrow?: boolean;\n /** Per-deployment PBKDF2 salt override. Must be supplied identically on encrypt and decrypt; omit for the shipped default. */\n kdfSalt?: string;\n /** PBKDF2 iteration count override. Must be supplied identically on encrypt and decrypt; omit for the shipped default. */\n kdfIterations?: number;\n}\n\n/** `iv` is encrypt-only: the envelope carries the IV, so decrypt reads it from there and a supplied one would be silently ignored. */\ninterface IAESExtraOptions extends IAESDecryptOptions {\n iv?: Buffer;\n}\n\nexport interface IAESKeyringEntry {\n id: string;\n secret: string;\n}\n\nexport type TAESSecret = string | IAESKeyringEntry[];\n\nexport type AESAlgorithmType = 'aes-256-cbc' | 'aes-256-gcm';\n\nexport class AES extends BaseCryptoAlgorithm<\n AESAlgorithmType,\n string,\n string,\n TAESSecret,\n string,\n string,\n IAESExtraOptions\n> {\n constructor(opts: { algorithm: AESAlgorithmType }) {\n super({ scope: AES.name, ...opts });\n }\n\n static withAlgorithm(algorithm: AESAlgorithmType) {\n return new AES({ algorithm });\n }\n\n protected resolveEncryptKey(opts: {\n secret: TAESSecret;\n kdfSalt?: string;\n kdfIterations?: number;\n }): { id: string; key: Buffer } {\n const { secret, kdfSalt, kdfIterations } = opts;\n const entry = Array.isArray(secret) ? secret[0] : { id: DEFAULT_KEY_ID, secret };\n\n if (!entry || isEmpty({ value: entry.secret })) {\n throw getError({ message: '[AES][resolveEncryptKey] Missing secret or empty keyring' });\n }\n\n const key = this.normalizeSecretKey({\n secret: entry.secret,\n length: this.getAlgorithmKeySize(),\n kdfSalt,\n kdfIterations,\n });\n return { id: entry.id, key };\n }\n\n protected resolveDecryptKey(opts: {\n secret: TAESSecret;\n id: string;\n kdfSalt?: string;\n kdfIterations?: number;\n }): Buffer {\n const { secret, id, kdfSalt, kdfIterations } = opts;\n const length = this.getAlgorithmKeySize();\n\n if (!Array.isArray(secret)) {\n return this.normalizeSecretKey({ secret, length, kdfSalt, kdfIterations });\n }\n\n const entry = secret.find((e) => e.id === id);\n if (!entry) {\n throw getError({\n message: `[AES][resolveDecryptKey] No key in keyring matches ciphertext key id \"${id}\"`,\n });\n }\n\n // Without this the empty secret derives a key from '' and fails as an opaque OpenSSL error, hiding a plain configuration mistake.\n if (isEmpty({ value: entry.secret })) {\n throw getError({\n message: `[AES][resolveDecryptKey] Keyring entry for key id \"${id}\" has an empty secret`,\n });\n }\n\n return this.normalizeSecretKey({ secret: entry.secret, length, kdfSalt, kdfIterations });\n }\n\n encrypt(opts: { message: string; secret: TAESSecret; opts?: IAESExtraOptions }) {\n const { message, secret } = opts;\n const {\n iv = C.randomBytes(DEFAULT_LENGTH),\n inputEncoding = 'utf-8',\n outputEncoding = 'base64',\n doThrow = true,\n kdfSalt,\n kdfIterations,\n } = opts.opts ?? {};\n\n try {\n const { id, key } = this.resolveEncryptKey({ secret, kdfSalt, kdfIterations });\n const idBuffer = Buffer.from(id, 'utf-8');\n if (idBuffer.length > 0xff) {\n throw getError({ message: '[AES][encrypt] Key id too long (max 255 bytes)' });\n }\n\n const cipher = C.createCipheriv(this.algorithm, key, iv);\n\n // Envelope: [version(1)][idLen(1)][id(idLen)][iv(16)][authTag(16, gcm only)][cipher]\n const header = Buffer.from([CIPHERTEXT_VERSION, idBuffer.length]);\n const parts = [header, idBuffer, iv];\n\n const cipherText = cipher.update(message, inputEncoding);\n const cipherFinal = cipher.final();\n\n switch (this.algorithm) {\n case 'aes-256-cbc': {\n break;\n }\n case 'aes-256-gcm': {\n parts.push((cipher as C.CipherGCM).getAuthTag());\n break;\n }\n }\n parts.push(cipherText);\n parts.push(cipherFinal);\n\n return Buffer.concat(parts).toString(outputEncoding);\n } catch (error) {\n if (doThrow) {\n throw error;\n }\n\n return message;\n }\n }\n\n encryptFile(opts: { absolutePath: string; secret: TAESSecret }): string {\n const { absolutePath, secret } = opts;\n\n if (!absolutePath || isEmpty({ value: absolutePath })) {\n return '';\n }\n\n const buffer = fs.readFileSync(absolutePath);\n const fileContent = buffer?.toString('utf-8');\n const encrypted = this.encrypt({ message: fileContent, secret });\n return encrypted;\n }\n\n decrypt(opts: { message: string; secret: TAESSecret; opts?: IAESDecryptOptions }) {\n const { message, secret } = opts;\n const {\n inputEncoding = 'base64',\n outputEncoding = 'utf-8',\n doThrow = true,\n kdfSalt,\n kdfIterations,\n } = opts.opts ?? {};\n\n try {\n const raw = Buffer.from(message, inputEncoding);\n\n const version = raw[0];\n if (version !== CIPHERTEXT_VERSION) {\n throw getError({ message: `[AES][decrypt] Unsupported ciphertext version: ${version}` });\n }\n\n const idLength = raw[1];\n let cursor = 2;\n\n const id = raw.subarray(cursor, cursor + idLength).toString('utf-8');\n cursor += idLength;\n\n const iv = raw.subarray(cursor, cursor + DEFAULT_LENGTH);\n cursor += DEFAULT_LENGTH;\n\n const key = this.resolveDecryptKey({ secret, id, kdfSalt, kdfIterations });\n const decipher = C.createDecipheriv(this.algorithm, key, iv);\n\n switch (this.algorithm) {\n case 'aes-256-cbc': {\n break;\n }\n case 'aes-256-gcm': {\n const authTag = raw.subarray(cursor, cursor + DEFAULT_LENGTH);\n cursor += DEFAULT_LENGTH;\n (decipher as C.DecipherGCM).setAuthTag(authTag);\n break;\n }\n }\n\n const cipherText = raw.subarray(cursor);\n return Buffer.concat([decipher.update(cipherText), decipher.final()]).toString(\n outputEncoding,\n );\n } catch (error) {\n if (doThrow) {\n throw error;\n }\n\n return message;\n }\n }\n\n decryptFile(opts: { absolutePath: string; secret: TAESSecret }) {\n const { absolutePath, secret } = opts;\n\n if (!absolutePath || isEmpty({ value: absolutePath })) {\n return '';\n }\n\n const buffer = fs.readFileSync(absolutePath);\n const fileContent = buffer?.toString('utf-8');\n const decrypted = this.decrypt({ message: fileContent, secret });\n return decrypted;\n }\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"app-env.d.ts","sourceRoot":"","sources":["../../../../src/modules/env/app-env.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAC5C,OAAO,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAC3C,OAAO,EAAE,KAAK,uBAAuB,EAAE,MAAM,UAAU,CAAC;AAExD,sPAAsP;AACtP,qBAAa,WAAY,SAAQ,gBAAgB;IAC/C,gNAAgN;IAChN,MAAM,KAAK,OAAO,IAAI,MAAM,GAAG,SAAS,CAGvC;IAED,MAAM,KAAK,OAAO,IAAI,MAAM,CAE3B;IAED,MAAM,CAAC,EAAE,CAAC,IAAI,EAAE;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE;CAGjC;AAED,qBAAa,sBAAuB,SAAQ,UAAW,YAAW,uBAAuB;IACvF,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,SAAS,CAA2B;gBAEhC,IAAI,EAAE;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAAC,CAAA;KAAE;IAcvF;;;;;;;;;;OAUG;IACH,GAAG,CAAC,UAAU,EAAE,mBAAmB,GAAG,OAAO,EAC3C,GAAG,EAAE,MAAM,EACX,IAAI,CAAC,EAAE;QACL,YAAY,CAAC,EAAE,UAAU,CAAC;QAC1B,SAAS,CAAC,EAAE,CAAC,KAAK,EAAE,mBAAmB,KAAK,UAAU,CAAC;KACxD,GACA,UAAU;IAcb,GAAG,CAAC,SAAS,EAAE,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,SAAS;IAI5C,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AG,CAAC,SAAS,EAAE,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,SAAS;IAI5C,KAAK,CAAC,IAAI,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;KAAE;IAO5C,aAAa;IAIb,IAAI;CAGL;AAoBD,eAAO,MAAM,sBAAsB,wBAAkC,CAAC;AAEtE,eAAO,MAAM,OAAO,wBAAyB,CAAC;AAC9C,eAAO,MAAM,IAAI,wBAAyB,CAAC"}
@@ -22,7 +22,7 @@ exports.Environment = Environment;
22
22
  class ApplicationEnvironment extends base_1.BaseHelper {
23
23
  constructor(opts) {
24
24
  super({ scope: ApplicationEnvironment.name });
25
- this.arguments = {};
25
+ this.arguments = Object.create(null);
26
26
  this.prefix = opts.prefix;
27
27
  for (const key in opts.envs) {
28
28
  if (!key.startsWith(this.prefix)) {
@@ -1 +1 @@
1
- {"version":3,"file":"app-env.js","sourceRoot":"","sources":["../../../../src/modules/env/app-env.ts"],"names":[],"mappings":";;;AAAA,6DAA6D;AAC7D,yCAA4C;AAC5C,mCAA2C;AAG3C,sPAAsP;AACtP,MAAa,WAAY,SAAQ,wBAAgB;IAC/C,gNAAgN;IAChN,MAAM,KAAK,OAAO;QAChB,MAAM,EAAE,QAAQ,EAAE,GAAG,OAAO,CAAC,GAAG,CAAC;QACjC,OAAO,QAAQ,CAAC;IAClB,CAAC;IAED,MAAM,KAAK,OAAO;QAChB,OAAO,WAAW,CAAC,OAAO,IAAI,WAAW,CAAC,WAAW,CAAC;IACxD,CAAC;IAED,MAAM,CAAC,EAAE,CAAC,IAAsB;QAC9B,OAAO,IAAI,CAAC,OAAO,KAAK,IAAI,CAAC,IAAI,CAAC;IACpC,CAAC;CACF;AAdD,kCAcC;AAED,MAAa,sBAAuB,SAAQ,iBAAU;IAIpD,YAAY,IAA2E;QACrF,KAAK,CAAC,EAAE,KAAK,EAAE,sBAAsB,CAAC,IAAI,EAAE,CAAC,CAAC;QAHxC,cAAS,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MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,WAAW,EAAE,CAAC;YACvC,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;QAC9B,CAAC;IACH,CAAC;IAED,aAAa;QACX,OAAO,WAAW,CAAC,OAAO,KAAK,aAAa,CAAC;IAC/C,CAAC;IAED,IAAI;QACF,OAAO,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;IACrC,CAAC;CACF;AAnED,wDAmEC;AAED,iNAAiN;AACjN,MAAM,aAAa,GAAG,MAAM,CAAC,GAAG,CAAC,+BAA+B,CAAC,CAAC;AAElE,MAAM,6BAA6B,GAAG,GAA2B,EAAE;IACjE,MAAM,MAAM,GAAuC,OAAO,CAAC,GAAG,CAAC,UAAU,EAAE,aAAa,CAAC,CAAC;IAC1F,IAAI,MAAM,EAAE,CAAC;QACX,OAAO,MAAM,CAAC;IAChB,CAAC;IAED,MAAM,OAAO,GAAG,IAAI,sBAAsB,CAAC;QACzC,MAAM,EAAE,IAAA,gCAAgB,EAAC,OAAO,CAAC,GAAG,CAAC,sBAAsB,CAAC,IAAI,SAAS;QACzE,IAAI,EAAE,OAAO,CAAC,GAAG;KAClB,CAAC,CAAC;IACH,OAAO,CAAC,GAAG,CAAC,UAAU,EAAE,aAAa,EAAE,OAAO,CAAC,CAAC;IAEhD,OAAO,OAAO,CAAC;AACjB,CAAC,CAAC;AAEW,QAAA,sBAAsB,GAAG,6BAA6B,EAAE,CAAC;AAEzD,QAAA,OAAO,GAAG,8BAAsB,CAAC;AACjC,QAAA,IAAI,GAAG,8BAAsB,CAAC","sourcesContent":["import { blankToUndefined } from '@/utilities/parse.utility';\nimport { BaseHelper } from '@/modules/base';\nimport { EnvironmentNames } from './names';\nimport { type IApplicationEnvironment } from './common';\n\n/** Adds the `NODE_ENV` reads to {@link EnvironmentNames}. Every name and set is inherited, so `Environment.PRODUCTION`, `Environment.COMMON_ENVS` and `Environment.DEVELOPMENT_ENVS` keep resolving here; only these two members need a `process`. */\nexport class Environment extends EnvironmentNames {\n /** `NODE_ENV` exactly as the host has it, `undefined` when unset. Destructured on purpose: `bun build` rewrites `process.env.NODE_ENV` to a literal at build time, a destructured read stays a runtime read. */\n static get ambient(): string | undefined {\n const { NODE_ENV } = process.env;\n return NODE_ENV;\n }\n\n static get current(): string {\n return Environment.ambient ?? Environment.DEVELOPMENT;\n }\n\n static is(opts: { name: string }) {\n return this.current === opts.name;\n }\n}\n\nexport class ApplicationEnvironment extends BaseHelper implements IApplicationEnvironment {\n private prefix: string;\n private arguments: Record<string, any> = {};\n\n constructor(opts: { prefix: string; envs: Record<string, string | number | undefined> }) {\n super({ scope: ApplicationEnvironment.name });\n\n this.prefix = opts.prefix;\n\n for (const key in opts.envs) {\n if (!key.startsWith(this.prefix)) {\n continue;\n }\n\n this.arguments[key] = opts.envs[key];\n }\n }\n\n /**\n * Reads one name. A line that is present but empty - `KEY=`, or padded to `KEY= ` by a hand\n * edit - is a pipeline that forgot to export the value, not a value: it is normalised to\n * `undefined` so `defaultValue` applies, and `transform` is handed that `undefined` rather than\n * the empty string.\n *\n * The normalisation runs ONLY when the caller supplied a `defaultValue`, because that call site\n * has already declared what it wants when the name carries nothing. A caller without one still\n * receives `''` unchanged, so no existing read changes shape. `'0'` and `'false'` are values and\n * are never normalised.\n */\n get<ReturnType, BeforeTransformType = unknown>(\n key: string,\n opts?: {\n defaultValue?: ReturnType;\n transform?: (value: BeforeTransformType) => ReturnType;\n },\n ): ReturnType {\n const raw = this.arguments[key];\n\n const isBlank = raw === undefined || raw === null || (typeof raw === 'string' && !raw.trim());\n const rs = opts?.defaultValue !== undefined && isBlank ? undefined : raw;\n\n if (!opts?.transform) {\n return (rs ?? opts?.defaultValue) as ReturnType;\n }\n\n const transformed = opts.transform(rs);\n return (transformed ?? opts?.defaultValue) as ReturnType;\n }\n\n set<ValueType>(key: string, value: ValueType) {\n this.arguments[key] = value;\n }\n\n merge(opts: { envs: Record<string, string> }) {\n const envsEntries = Object.entries(opts.envs);\n for (const [key, value] of envsEntries) {\n this.arguments[key] = value;\n }\n }\n\n isDevelopment() {\n return Environment.ambient === 'development';\n }\n\n keys() {\n return Object.keys(this.arguments);\n }\n}\n\n/** A process can carry two copies of this module - an application's ESM import beside a CommonJS require. The instance lives in this globalThis slot so a `set()` through one copy is read through the other. */\nconst INSTANCE_SLOT = Symbol.for('ignis:application-environment');\n\nconst resolveApplicationEnvironment = (): ApplicationEnvironment => {\n const shared: ApplicationEnvironment | undefined = Reflect.get(globalThis, INSTANCE_SLOT);\n if (shared) {\n return shared;\n }\n\n const created = new ApplicationEnvironment({\n prefix: blankToUndefined(process.env.APPLICATION_ENV_PREFIX) ?? 'APP_ENV',\n envs: process.env,\n });\n Reflect.set(globalThis, INSTANCE_SLOT, created);\n\n return created;\n};\n\nexport const applicationEnvironment = resolveApplicationEnvironment();\n\nexport const AppEnvs = applicationEnvironment;\nexport const Envs = applicationEnvironment;\n"]}
1
+ {"version":3,"file":"app-env.js","sourceRoot":"","sources":["../../../../src/modules/env/app-env.ts"],"names":[],"mappings":";;;AAAA,6DAA6D;AAC7D,yCAA4C;AAC5C,mCAA2C;AAG3C,sPAAsP;AACtP,MAAa,WAAY,SAAQ,wBAAgB;IAC/C,gNAAgN;IAChN,MAAM,KAAK,OAAO;QAChB,MAAM,EAAE,QAAQ,EAAE,GAAG,OAAO,CAAC,GAAG,CAAC;QACjC,OAAO,QAAQ,CAAC;IAClB,CAAC;IAED,MAAM,KAAK,OAAO;QAChB,OAAO,WAAW,CAAC,OAAO,IAAI,WAAW,CAAC,WAAW,CAAC;IACxD,CAAC;IAED,MAAM,CAAC,EAAE,CAAC,IAAsB;QAC9B,OAAO,IAAI,CAAC,OAAO,KAAK,IAAI,CAAC,IAAI,CAAC;IACpC,CAAC;CACF;AAdD,kCAcC;AAED,MAAa,sBAAuB,SAAQ,iBAAU;IAIpD,YAAY,IAA2E;QACrF,KAAK,CAAC,EAAE,KAAK,EAAE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AM,WAAW,GAAG,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAC9C,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,WAAW,EAAE,CAAC;YACvC,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;QAC9B,CAAC;IACH,CAAC;IAED,aAAa;QACX,OAAO,WAAW,CAAC,OAAO,KAAK,aAAa,CAAC;IAC/C,CAAC;IAED,IAAI;QACF,OAAO,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;IACrC,CAAC;CACF;AAnED,wDAmEC;AAED,iNAAiN;AACjN,MAAM,aAAa,GAAG,MAAM,CAAC,GAAG,CAAC,+BAA+B,CAAC,CAAC;AAElE,MAAM,6BAA6B,GAAG,GAA2B,EAAE;IACjE,MAAM,MAAM,GAAuC,OAAO,CAAC,GAAG,CAAC,UAAU,EAAE,aAAa,CAAC,CAAC;IAC1F,IAAI,MAAM,EAAE,CAAC;QACX,OAAO,MAAM,CAAC;IAChB,CAAC;IAED,MAAM,OAAO,GAAG,IAAI,sBAAsB,CAAC;QACzC,MAAM,EAAE,IAAA,gCAAgB,EAAC,OAAO,CAAC,GAAG,CAAC,sBAAsB,CAAC,IAAI,SAAS;QACzE,IAAI,EAAE,OAAO,CAAC,GAAG;KAClB,CAAC,CAAC;IACH,OAAO,CAAC,GAAG,CAAC,UAAU,EAAE,aAAa,EAAE,OAAO,CAAC,CAAC;IAEhD,OAAO,OAAO,CAAC;AACjB,CAAC,CAAC;AAEW,QAAA,sBAAsB,GAAG,6BAA6B,EAAE,CAAC;AAEzD,QAAA,OAAO,GAAG,8BAAsB,CAAC;AACjC,QAAA,IAAI,GAAG,8BAAsB,CAAC","sourcesContent":["import { blankToUndefined } from '@/utilities/parse.utility';\nimport { BaseHelper } from '@/modules/base';\nimport { EnvironmentNames } from './names';\nimport { type IApplicationEnvironment } from './common';\n\n/** Adds the `NODE_ENV` reads to {@link EnvironmentNames}. Every name and set is inherited, so `Environment.PRODUCTION`, `Environment.COMMON_ENVS` and `Environment.DEVELOPMENT_ENVS` keep resolving here; only these two members need a `process`. */\nexport class Environment extends EnvironmentNames {\n /** `NODE_ENV` exactly as the host has it, `undefined` when unset. Destructured on purpose: `bun build` rewrites `process.env.NODE_ENV` to a literal at build time, a destructured read stays a runtime read. */\n static get ambient(): string | undefined {\n const { NODE_ENV } = process.env;\n return NODE_ENV;\n }\n\n static get current(): string {\n return Environment.ambient ?? Environment.DEVELOPMENT;\n }\n\n static is(opts: { name: string }) {\n return this.current === opts.name;\n }\n}\n\nexport class ApplicationEnvironment extends BaseHelper implements IApplicationEnvironment {\n private prefix: string;\n private arguments: Record<string, any> = Object.create(null);\n\n constructor(opts: { prefix: string; envs: Record<string, string | number | undefined> }) {\n super({ scope: ApplicationEnvironment.name });\n\n this.prefix = opts.prefix;\n\n for (const key in opts.envs) {\n if (!key.startsWith(this.prefix)) {\n continue;\n }\n\n this.arguments[key] = opts.envs[key];\n }\n }\n\n /**\n * Reads one name. A line that is present but empty - `KEY=`, or padded to `KEY= ` by a hand\n * edit - is a pipeline that forgot to export the value, not a value: it is normalised to\n * `undefined` so `defaultValue` applies, and `transform` is handed that `undefined` rather than\n * the empty string.\n *\n * The normalisation runs ONLY when the caller supplied a `defaultValue`, because that call site\n * has already declared what it wants when the name carries nothing. A caller without one still\n * receives `''` unchanged, so no existing read changes shape. `'0'` and `'false'` are values and\n * are never normalised.\n */\n get<ReturnType, BeforeTransformType = unknown>(\n key: string,\n opts?: {\n defaultValue?: ReturnType;\n transform?: (value: BeforeTransformType) => ReturnType;\n },\n ): ReturnType {\n const raw = this.arguments[key];\n\n const isBlank = raw === undefined || raw === null || (typeof raw === 'string' && !raw.trim());\n const rs = opts?.defaultValue !== undefined && isBlank ? undefined : raw;\n\n if (!opts?.transform) {\n return (rs ?? opts?.defaultValue) as ReturnType;\n }\n\n const transformed = opts.transform(rs);\n return (transformed ?? opts?.defaultValue) as ReturnType;\n }\n\n set<ValueType>(key: string, value: ValueType) {\n this.arguments[key] = value;\n }\n\n merge(opts: { envs: Record<string, string> }) {\n const envsEntries = Object.entries(opts.envs);\n for (const [key, value] of envsEntries) {\n this.arguments[key] = value;\n }\n }\n\n isDevelopment() {\n return Environment.ambient === 'development';\n }\n\n keys() {\n return Object.keys(this.arguments);\n }\n}\n\n/** A process can carry two copies of this module - an application's ESM import beside a CommonJS require. The instance lives in this globalThis slot so a `set()` through one copy is read through the other. */\nconst INSTANCE_SLOT = Symbol.for('ignis:application-environment');\n\nconst resolveApplicationEnvironment = (): ApplicationEnvironment => {\n const shared: ApplicationEnvironment | undefined = Reflect.get(globalThis, INSTANCE_SLOT);\n if (shared) {\n return shared;\n }\n\n const created = new ApplicationEnvironment({\n prefix: blankToUndefined(process.env.APPLICATION_ENV_PREFIX) ?? 'APP_ENV',\n envs: process.env,\n });\n Reflect.set(globalThis, INSTANCE_SLOT, created);\n\n return created;\n};\n\nexport const applicationEnvironment = resolveApplicationEnvironment();\n\nexport const AppEnvs = applicationEnvironment;\nexport const Envs = applicationEnvironment;\n"]}
@@ -15,7 +15,7 @@ class LoggerFormats {
15
15
  }
16
16
  exports.LoggerFormats = LoggerFormats;
17
17
  // -------------------------------------------------------------
18
- const extraLogEnvs = (process.env.APP_ENV_EXTRA_LOG_ENVS ?? '').split(',').map(el => el.trim());
18
+ const extraLogEnvs = (process.env.APP_ENV_EXTRA_LOG_ENVS ?? '').split(',').map((el) => el.trim());
19
19
  const LOG_ENVIRONMENTS = new Set([...Array.from(env_1.Environment.COMMON_ENVS), ...extraLogEnvs]);
20
20
  /** debug() gate, computed ONCE at module load: DEBUG truthy and NODE_ENV unset or allowlisted. Shared across every logger implementation - runtime env changes need a restart. */
21
21
  const { DEBUG } = process.env;
@@ -1 +1 @@
1
- {"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../../../src/modules/logger/common/constants.ts"],"names":[],"mappings":";;;AACA,uCAA4C;AAC5C,6D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AW,EAAE,CAAC;IACnD,IAAI,CAAC,iBAAS,CAAC,OAAO,CAAC,UAAU,CAAC,EAAE,CAAC;QACnC,gJAAgJ;QAChJ,OAAO,CAAC,IAAI,CACV,mFAAmF,EACnF,UAAU,EACV,CAAC,GAAG,iBAAS,CAAC,UAAU,CAAC,EACzB,iBAAS,CAAC,KAAK,CAChB,CAAC;QACF,OAAO,iBAAS,CAAC,KAAK,CAAC;IACzB,CAAC;IAED,OAAO,UAAuB,CAAC;AACjC,CAAC,CAAC;AApBW,QAAA,kBAAkB,sBAoB7B;AAEF;;;;;;;;;;;;GAYG;AACI,MAAM,qBAAqB,GAAG,CAAC,IAGrC,EAAuB,EAAE;IACxB,MAAM,UAAU,GAAG,IAAI,EAAE,UAAU,IAAI,OAAO,CAAC,GAAG,CAAC,oBAAoB,CAAC;IACxE,IAAI,UAAU,KAAK,SAAS,IAAI,UAAU,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC;QACzD,OAAO,IAAA,yBAAS,EAAC,UAAU,CAAC,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC,CAAC;IACpD,CAAC;IAED,MAAM,OAAO,GAAG,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC;IACrC,IAAI,OAAO,KAAK,SAAS,IAAI,OAAO,KAAK,EAAE,EAAE,CAAC;QAC5C,OAAO,KAAK,CAAC;IACf,CAAC;IAED,MAAM,WAAW,GAAG,IAAI,EAAE,WAAW,IAAI,iBAAW,CAAC,OAAO,CAAC;IAC7D,IAAI,CAAC,iBAAW,CAAC,gBAAgB,CAAC,GAAG,CAAC,WAAW,CAAC,EAAE,CAAC;QACnD,OAAO,KAAK,CAAC;IACf,CAAC;IAED,OAAO,SAAS,CAAC;AACnB,CAAC,CAAC;AApBW,QAAA,qBAAqB,yBAoBhC","sourcesContent":["import { type TConstValue } from '@/common/types';\nimport { Environment } from '@/modules/env';\nimport { toBoolean } from '@/utilities/parse.utility';\nimport { LogLevels, type TLogLevel } from './types';\n\n// -------------------------------------------------------------\nexport class LoggerFormats {\n static readonly JSON = 'json';\n static readonly TEXT = 'text';\n\n static readonly SCHEME_SET = new Set([this.JSON, this.TEXT]);\n\n static isValid(input: string): input is TLoggerFormat {\n return this.SCHEME_SET.has(input);\n }\n}\n\nexport type TLoggerFormat = TConstValue<typeof LoggerFormats>;\n\n// -------------------------------------------------------------\nconst extraLogEnvs = (process.env.APP_ENV_EXTRA_LOG_ENVS ?? '').split(',').map(el => el.trim());\nconst LOG_ENVIRONMENTS = new Set([...Array.from(Environment.COMMON_ENVS), ...extraLogEnvs]);\n\n/** debug() gate, computed ONCE at module load: DEBUG truthy and NODE_ENV unset or allowlisted. Shared across every logger implementation - runtime env changes need a restart. */\nconst { DEBUG } = process.env;\nexport const SHOULD_LOG_DEBUG =\n toBoolean(DEBUG) && (!Environment.ambient || LOG_ENVIRONMENTS.has(Environment.ambient));\n\n/** The logger's own level, below which a line never reaches ANY transport. Defaults to `debug` - level gating belongs to the wrapper and each transport, and a stricter default here would silently drop lines the wrapper already let through. */\nexport const resolveLoggerLevel = (opts: { configured?: string }): TLogLevel => {\n const { configured } = opts;\n\n if (!configured || configured.trim() === '') {\n return LogLevels.DEBUG;\n }\n\n const normalized = configured.trim().toLowerCase();\n if (!LogLevels.isValid(normalized)) {\n // console, not Logger: the logger is being built - routing this warning through it would re-enter the very pipeline that is not configured yet.\n console.warn(\n '[resolveLoggerLevel] Invalid logger level | value: %s | valids: %s | fallback: %s',\n configured,\n [...LogLevels.SCHEME_SET],\n LogLevels.DEBUG,\n );\n return LogLevels.DEBUG;\n }\n\n return normalized as TLogLevel;\n};\n\n/**\n * Whether log lines may carry ANSI color, resolved at CALL time. First match wins:\n *\n * 1. `APP_ENV_LOGGER_COLOR` - an explicit yes or no from the operator.\n * 2. `NO_COLOR`, set to anything non-empty - the no-color.org convention.\n * 3. `NODE_ENV` outside {@link Environment.DEVELOPMENT_ENVS} - production, staging, uat and any\n * unrecognized name. Fail-closed, the same boundary the error sanitizer draws: colors are a\n * terminal affordance, and in a deployed environment the same bytes land in a file or an\n * aggregator as escape noise every grep then has to strip.\n *\n * `undefined` means the framework has no opinion, so a provider that detects a terminal itself\n * keeps deciding - which is why the pino path forwards nothing in that case.\n */\nexport const resolveLoggerColorize = (opts?: {\n configured?: string;\n environment?: string;\n}): boolean | undefined => {\n const configured = opts?.configured ?? process.env.APP_ENV_LOGGER_COLOR;\n if (configured !== undefined && configured.trim() !== '') {\n return toBoolean(configured.trim().toLowerCase());\n }\n\n const noColor = process.env.NO_COLOR;\n if (noColor !== undefined && noColor !== '') {\n return false;\n }\n\n const environment = opts?.environment ?? Environment.current;\n if (!Environment.DEVELOPMENT_ENVS.has(environment)) {\n return false;\n }\n\n return undefined;\n};\n"]}
1
+ {"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../../../src/modules/logger/common/constants.ts"],"names":[],"mappings":";;;AACA,uCAA4C;AAC5C,6DAAsD;AACtD,mCAAoD;AAEpD,gEAAgE;AAChE,MAAa,aAAa;aACR,SAAI,GAAG,MAAM,CAAC;aACd,SAAI,GAAG,MAAM,CAAC;aAEd,eAAU,GAAG,IAAI,GAAG,CAAC,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;IAE7D,MAAM,CAAC,OAAO,CAAC,KAAa;QAC1B,OAAO,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;IACpC,CAAC;;AARH,sCASC;AAID,gEAAgE;AAChE,MAAM,YAAY,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,sBAAsB,IAAI,EAAE,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,IAAI,EAAE,CAAC,CAAC;AAClG,MAAM,gBAAgB,GAAG,IAAI,GAAG,CAAC,CAAC,GAAG,KAAK,CAAC,IAAI,CAAC,iBAAW,CAAC,WAAW,CAAC,EAAE,G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WAAW,EAAE,CAAC,CAAC;IACpD,CAAC;IAED,MAAM,OAAO,GAAG,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC;IACrC,IAAI,OAAO,KAAK,SAAS,IAAI,OAAO,KAAK,EAAE,EAAE,CAAC;QAC5C,OAAO,KAAK,CAAC;IACf,CAAC;IAED,MAAM,WAAW,GAAG,IAAI,EAAE,WAAW,IAAI,iBAAW,CAAC,OAAO,CAAC;IAC7D,IAAI,CAAC,iBAAW,CAAC,gBAAgB,CAAC,GAAG,CAAC,WAAW,CAAC,EAAE,CAAC;QACnD,OAAO,KAAK,CAAC;IACf,CAAC;IAED,OAAO,SAAS,CAAC;AACnB,CAAC,CAAC;AApBW,QAAA,qBAAqB,yBAoBhC","sourcesContent":["import { type TConstValue } from '@/common/types';\nimport { Environment } from '@/modules/env';\nimport { toBoolean } from '@/utilities/parse.utility';\nimport { LogLevels, type TLogLevel } from './types';\n\n// -------------------------------------------------------------\nexport class LoggerFormats {\n static readonly JSON = 'json';\n static readonly TEXT = 'text';\n\n static readonly SCHEME_SET = new Set([this.JSON, this.TEXT]);\n\n static isValid(input: string): input is TLoggerFormat {\n return this.SCHEME_SET.has(input);\n }\n}\n\nexport type TLoggerFormat = TConstValue<typeof LoggerFormats>;\n\n// -------------------------------------------------------------\nconst extraLogEnvs = (process.env.APP_ENV_EXTRA_LOG_ENVS ?? '').split(',').map((el) => el.trim());\nconst LOG_ENVIRONMENTS = new Set([...Array.from(Environment.COMMON_ENVS), ...extraLogEnvs]);\n\n/** debug() gate, computed ONCE at module load: DEBUG truthy and NODE_ENV unset or allowlisted. Shared across every logger implementation - runtime env changes need a restart. */\nconst { DEBUG } = process.env;\nexport const SHOULD_LOG_DEBUG =\n toBoolean(DEBUG) && (!Environment.ambient || LOG_ENVIRONMENTS.has(Environment.ambient));\n\n/** The logger's own level, below which a line never reaches ANY transport. Defaults to `debug` - level gating belongs to the wrapper and each transport, and a stricter default here would silently drop lines the wrapper already let through. */\nexport const resolveLoggerLevel = (opts: { configured?: string }): TLogLevel => {\n const { configured } = opts;\n\n if (!configured || configured.trim() === '') {\n return LogLevels.DEBUG;\n }\n\n const normalized = configured.trim().toLowerCase();\n if (!LogLevels.isValid(normalized)) {\n // console, not Logger: the logger is being built - routing this warning through it would re-enter the very pipeline that is not configured yet.\n console.warn(\n '[resolveLoggerLevel] Invalid logger level | value: %s | valids: %s | fallback: %s',\n configured,\n [...LogLevels.SCHEME_SET],\n LogLevels.DEBUG,\n );\n return LogLevels.DEBUG;\n }\n\n return normalized as TLogLevel;\n};\n\n/**\n * Whether log lines may carry ANSI color, resolved at CALL time. First match wins:\n *\n * 1. `APP_ENV_LOGGER_COLOR` - an explicit yes or no from the operator.\n * 2. `NO_COLOR`, set to anything non-empty - the no-color.org convention.\n * 3. `NODE_ENV` outside {@link Environment.DEVELOPMENT_ENVS} - production, staging, uat and any\n * unrecognized name. Fail-closed, the same boundary the error sanitizer draws: colors are a\n * terminal affordance, and in a deployed environment the same bytes land in a file or an\n * aggregator as escape noise every grep then has to strip.\n *\n * `undefined` means the framework has no opinion, so a provider that detects a terminal itself\n * keeps deciding - which is why the pino path forwards nothing in that case.\n */\nexport const resolveLoggerColorize = (opts?: {\n configured?: string;\n environment?: string;\n}): boolean | undefined => {\n const configured = opts?.configured ?? process.env.APP_ENV_LOGGER_COLOR;\n if (configured !== undefined && configured.trim() !== '') {\n return toBoolean(configured.trim().toLowerCase());\n }\n\n const noColor = process.env.NO_COLOR;\n if (noColor !== undefined && noColor !== '') {\n return false;\n }\n\n const environment = opts?.environment ?? Environment.current;\n if (!Environment.DEVELOPMENT_ENVS.has(environment)) {\n return false;\n }\n\n return undefined;\n};\n"]}
@@ -102,5 +102,5 @@ exports.ApplicationLogger = {
102
102
  get: (scope) => LoggerFactory.getLogger([scope]),
103
103
  };
104
104
  // Runs whenever LoggerFactory is imported as a value - which core's Container and every application entrypoint already do. This is what makes BaseHelper resolve real loggers on the server while its own import graph stays browser-pure.
105
- resolver_1.LoggerResolver.use({ resolver: opts => LoggerFactory.getLogger(opts.scopes) });
105
+ resolver_1.LoggerResolver.use({ resolver: (opts) => LoggerFactory.getLogger(opts.scopes) });
106
106
  //# sourceMappingURL=factory.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"factory.js","sourceRoot":"","sources":["../../../../src/modules/logger/factory.ts"],"names":[],"mappings":";;;AACA,8DAAoD;AACpD,6CAA4C;AAC5C,8CAAiD;AAEjD,yCAA4C;AAE5C,8PAA8P;AAC9P,MAAM,eAAgB,SAAQ,yBAAc;IAG1C,YAA6B,KAAa;QACxC,KAAK,EAAE,CAAC;QADmB,UAAK,GAAL,KAAK,CAAQ;IAE1C,CAAC;IAED,OAAO,CAAC,QAAyB;QAC/B,IAAI,CAAC,SAAS,GAAG,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAC5C,CAAC;IAEO,QAAQ;QACd,mEAAmE;QACnE,OAAO,CAAC,IAAI,CAAC,SAAS,KAAK,aAAa,CAAC,eAAe,EAAE,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC;IAC9E,CAAC;IAED,KAAK,CAAC,OAAe,EAAE,GAAG,IAAe;QACvC,IAAI,CAAC,QAAQ,EAAE,CAAC,KAAK,CAAC,OAAO,EAAE,GAAG,IAAI,CAAC,CAAC;IAC1C,CAAC;IAED,IAAI,CAAC,OAAe,EAAE,GAAG,IAAe;QACtC,IAAI,CAAC,QAAQ,EAAE,CAAC,IAAI,CAAC,OAAO,EAAE,GAAG,IAAI,CAAC,CAAC;IACzC,CAAC;IAED,IAAI,CAAC,OAAe,EAAE,GAAG,IAAe;QACtC,IAAI,CAAC,QAAQ,EAAE,CAAC,IAAI,CAAC,OAAO,EAAE,GAAG,IAAI,CAAC,CAAC;IACzC,CAAC;IAED,KAAK,CAAC,OAAe,EAAE,GAAG,IAAe;QACvC,IAAI,CAAC,QAAQ,EAAE,CAAC,KAAK,CAAC,OAAO,EAAE,GAAG,IAA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AC;QAChC,CAAC;QAED,OAAO,MAAM,CAAC;IAChB,CAAC;;AAzDH,sCA0DC;AAED,kFAAkF;AACrE,QAAA,iBAAiB,GAAG;IAC/B,GAAG,EAAE,CAAC,KAAa,EAAW,EAAE,CAAC,aAAa,CAAC,SAAS,CAAC,CAAC,KAAK,CAAC,CAAC;CAClE,CAAC;AAEF,2OAA2O;AAC3O,yBAAc,CAAC,GAAG,CAAC,EAAE,QAAQ,EAAE,IAAI,CAAC,EAAE,CAAC,aAAa,CAAC,SAAS,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC","sourcesContent":["import { type AnyType } from '@/common/types';\nimport { getError } from '@venizia/ignis-inversion';\nimport { createRequire } from 'node:module';\nimport { AbstractLogger } from './base/abstract';\nimport { type ILogger, type ILoggerProvider, type TLogLevel } from './common/types';\nimport { LoggerResolver } from './resolver';\n\n/** Stable wrapper the factory hands out; the delegate resolves lazily (first log call or `use()`), never at construction, so no provider loads until needed. Mutual reference with LoggerFactory is by design - hence the `no-use-before-define` disables. */\nclass LoggerDelegator extends AbstractLogger {\n private _delegate?: ILogger;\n\n constructor(private readonly scope: string) {\n super();\n }\n\n repoint(provider: ILoggerProvider): void {\n this._delegate = provider.get(this.scope);\n }\n\n private delegate(): ILogger {\n // eslint-disable-next-line @typescript-eslint/no-use-before-define\n return (this._delegate ??= LoggerFactory.currentProvider().get(this.scope));\n }\n\n debug(message: string, ...args: AnyType[]) {\n this.delegate().debug(message, ...args);\n }\n\n info(message: string, ...args: AnyType[]) {\n this.delegate().info(message, ...args);\n }\n\n warn(message: string, ...args: AnyType[]) {\n this.delegate().warn(message, ...args);\n }\n\n error(message: string, ...args: AnyType[]) {\n this.delegate().error(message, ...args);\n }\n\n emerg(message: string, ...args: AnyType[]) {\n this.delegate().emerg(message, ...args);\n }\n\n log(level: TLogLevel, message: string, ...args: AnyType[]) {\n this.delegate().log(level, message, ...args);\n }\n\n for(methodName: string): ILogger {\n const childScope = this.scope !== '' ? `${this.scope}-${methodName}` : methodName;\n // eslint-disable-next-line @typescript-eslint/no-use-before-define\n return LoggerFactory.getLogger([childScope]);\n }\n}\n\n/** A bundle can carry two copies of this module - the application's ESM import and core's CJS require. The provider lives in this globalThis slot so `use()` in one copy is seen by the other. */\nconst PROVIDER_SLOT = Symbol.for('ignis:logger-provider');\n\n/** Provider-agnostic acquisition path. Exactly ONE provider is ever loaded - the one registered via `use()`, or the winston default at first unregistered log call. */\nexport class LoggerFactory {\n private static provider?: ILoggerProvider;\n private static cache = new Map<string, LoggerDelegator>();\n\n /** Register the application's provider. Re-points every wrapper issued so far. */\n static use(opts: { provider: ILoggerProvider }): void {\n this.provider = opts.provider;\n Reflect.set(globalThis, PROVIDER_SLOT, opts.provider);\n const cacheValues = this.cache.values();\n for (const wrapper of cacheValues) {\n wrapper.repoint(opts.provider);\n }\n }\n\n static currentProvider(): ILoggerProvider {\n if (!this.provider) {\n this.provider = this.sharedProvider() ?? this.loadDefaultProvider();\n Reflect.set(globalThis, PROVIDER_SLOT, this.provider);\n }\n\n return this.provider;\n }\n\n /** The provider another copy of this module registered, if any. */\n private static sharedProvider(): ILoggerProvider | undefined {\n const shared: ILoggerProvider | undefined = Reflect.get(globalThis, PROVIDER_SLOT);\n return shared;\n }\n\n // winston is an optional peer; compiled binaries must register a provider explicitly because only a class reference carries a provider into a bundle.\n private static loadDefaultProvider(): ILoggerProvider {\n try {\n return createRequire(__filename)('./winston').WinstonLogger;\n } catch (error) {\n throw getError({\n message: [\n '[LoggerFactory] No logger provider is registered and the default (winston) could not be loaded.',\n 'Either install it: `bun add winston winston-transport winston-daily-rotate-file`,',\n 'or register a provider at your entrypoint: `LoggerFactory.use({ provider })` with a class',\n \"from '@venizia/ignis-helpers/winston' or '@venizia/ignis-helpers/pino'.\",\n 'Compiled binaries (bun build --compile) MUST register explicitly.',\n `Cause: ${error instanceof Error ? error.message : String(error)}`,\n ].join(' '),\n });\n }\n }\n\n static getLogger(scopes: string[]): ILogger {\n const scope = scopes.join('-');\n let cached = this.cache.get(scope);\n\n if (!cached) {\n cached = new LoggerDelegator(scope);\n this.cache.set(scope, cached);\n }\n\n return cached;\n }\n}\n\n/** Provider-following facade: always resolves through the registered provider. */\nexport const ApplicationLogger = {\n get: (scope: string): ILogger => LoggerFactory.getLogger([scope]),\n};\n\n// Runs whenever LoggerFactory is imported as a value - which core's Container and every application entrypoint already do. This is what makes BaseHelper resolve real loggers on the server while its own import graph stays browser-pure.\nLoggerResolver.use({ resolver: opts => LoggerFactory.getLogger(opts.scopes) });\n"]}
1
+ {"version":3,"file":"factory.js","sourceRoot":"","sources":["../../../../src/modules/logger/factory.ts"],"names":[],"mappings":";;;AACA,8DAAoD;AACpD,6CAA4C;AAC5C,8CAAiD;AAEjD,yCAA4C;AAE5C,8PAA8P;AAC9P,MAAM,eAAgB,SAAQ,yBAAc;IAG1C,YAA6B,KAAa;QACxC,KAAK,EAAE,CAAC;QADmB,UAAK,GAAL,KAAK,CAAQ;IAE1C,CAAC;IAED,OAAO,CAAC,QAAyB;QAC/B,IAAI,CAAC,SAAS,GAAG,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAC5C,CAAC;IAEO,QAAQ;QACd,mEAAmE;QACnE,OAAO,CAAC,IAAI,CAAC,SAAS,KAAK,aAAa,CAAC,eAAe,EAAE,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC;IAC9E,CAAC;IAED,KAAK,CAAC,OAAe,EAAE,GAAG,IAAe;QACvC,IAAI,CAAC,QAAQ,EAAE,CAAC,KAAK,CAAC,OAAO,EAAE,GAAG,IAAI,CAAC,CAAC;IAC1C,CAAC;IAED,IAAI,CAAC,OAAe,EAAE,GAAG,IAAe;QACtC,IAAI,CAAC,QAAQ,EAAE,CAAC,IAAI,CAAC,OAAO,EAAE,GAAG,IAAI,CAAC,CAAC;IACzC,CAAC;IAED,IAAI,CAAC,OAAe,EAAE,GAAG,IAAe;QACtC,IAAI,CAA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AC,GAAG,CAAC,KAAK,CAAC,CAAC;QAEnC,IAAI,CAAC,MAAM,EAAE,CAAC;YACZ,MAAM,GAAG,IAAI,eAAe,CAAC,KAAK,CAAC,CAAC;YACpC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;QAChC,CAAC;QAED,OAAO,MAAM,CAAC;IAChB,CAAC;;AAzDH,sCA0DC;AAED,kFAAkF;AACrE,QAAA,iBAAiB,GAAG;IAC/B,GAAG,EAAE,CAAC,KAAa,EAAW,EAAE,CAAC,aAAa,CAAC,SAAS,CAAC,CAAC,KAAK,CAAC,CAAC;CAClE,CAAC;AAEF,2OAA2O;AAC3O,yBAAc,CAAC,GAAG,CAAC,EAAE,QAAQ,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,aAAa,CAAC,SAAS,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC","sourcesContent":["import { type AnyType } from '@/common/types';\nimport { getError } from '@venizia/ignis-inversion';\nimport { createRequire } from 'node:module';\nimport { AbstractLogger } from './base/abstract';\nimport { type ILogger, type ILoggerProvider, type TLogLevel } from './common/types';\nimport { LoggerResolver } from './resolver';\n\n/** Stable wrapper the factory hands out; the delegate resolves lazily (first log call or `use()`), never at construction, so no provider loads until needed. Mutual reference with LoggerFactory is by design - hence the `no-use-before-define` disables. */\nclass LoggerDelegator extends AbstractLogger {\n private _delegate?: ILogger;\n\n constructor(private readonly scope: string) {\n super();\n }\n\n repoint(provider: ILoggerProvider): void {\n this._delegate = provider.get(this.scope);\n }\n\n private delegate(): ILogger {\n // eslint-disable-next-line @typescript-eslint/no-use-before-define\n return (this._delegate ??= LoggerFactory.currentProvider().get(this.scope));\n }\n\n debug(message: string, ...args: AnyType[]) {\n this.delegate().debug(message, ...args);\n }\n\n info(message: string, ...args: AnyType[]) {\n this.delegate().info(message, ...args);\n }\n\n warn(message: string, ...args: AnyType[]) {\n this.delegate().warn(message, ...args);\n }\n\n error(message: string, ...args: AnyType[]) {\n this.delegate().error(message, ...args);\n }\n\n emerg(message: string, ...args: AnyType[]) {\n this.delegate().emerg(message, ...args);\n }\n\n log(level: TLogLevel, message: string, ...args: AnyType[]) {\n this.delegate().log(level, message, ...args);\n }\n\n for(methodName: string): ILogger {\n const childScope = this.scope !== '' ? `${this.scope}-${methodName}` : methodName;\n // eslint-disable-next-line @typescript-eslint/no-use-before-define\n return LoggerFactory.getLogger([childScope]);\n }\n}\n\n/** A bundle can carry two copies of this module - the application's ESM import and core's CJS require. The provider lives in this globalThis slot so `use()` in one copy is seen by the other. */\nconst PROVIDER_SLOT = Symbol.for('ignis:logger-provider');\n\n/** Provider-agnostic acquisition path. Exactly ONE provider is ever loaded - the one registered via `use()`, or the winston default at first unregistered log call. */\nexport class LoggerFactory {\n private static provider?: ILoggerProvider;\n private static cache = new Map<string, LoggerDelegator>();\n\n /** Register the application's provider. Re-points every wrapper issued so far. */\n static use(opts: { provider: ILoggerProvider }): void {\n this.provider = opts.provider;\n Reflect.set(globalThis, PROVIDER_SLOT, opts.provider);\n const cacheValues = this.cache.values();\n for (const wrapper of cacheValues) {\n wrapper.repoint(opts.provider);\n }\n }\n\n static currentProvider(): ILoggerProvider {\n if (!this.provider) {\n this.provider = this.sharedProvider() ?? this.loadDefaultProvider();\n Reflect.set(globalThis, PROVIDER_SLOT, this.provider);\n }\n\n return this.provider;\n }\n\n /** The provider another copy of this module registered, if any. */\n private static sharedProvider(): ILoggerProvider | undefined {\n const shared: ILoggerProvider | undefined = Reflect.get(globalThis, PROVIDER_SLOT);\n return shared;\n }\n\n // winston is an optional peer; compiled binaries must register a provider explicitly because only a class reference carries a provider into a bundle.\n private static loadDefaultProvider(): ILoggerProvider {\n try {\n return createRequire(__filename)('./winston').WinstonLogger;\n } catch (error) {\n throw getError({\n message: [\n '[LoggerFactory] No logger provider is registered and the default (winston) could not be loaded.',\n 'Either install it: `bun add winston winston-transport winston-daily-rotate-file`,',\n 'or register a provider at your entrypoint: `LoggerFactory.use({ provider })` with a class',\n \"from '@venizia/ignis-helpers/winston' or '@venizia/ignis-helpers/pino'.\",\n 'Compiled binaries (bun build --compile) MUST register explicitly.',\n `Cause: ${error instanceof Error ? error.message : String(error)}`,\n ].join(' '),\n });\n }\n }\n\n static getLogger(scopes: string[]): ILogger {\n const scope = scopes.join('-');\n let cached = this.cache.get(scope);\n\n if (!cached) {\n cached = new LoggerDelegator(scope);\n this.cache.set(scope, cached);\n }\n\n return cached;\n }\n}\n\n/** Provider-following facade: always resolves through the registered provider. */\nexport const ApplicationLogger = {\n get: (scope: string): ILogger => LoggerFactory.getLogger([scope]),\n};\n\n// Runs whenever LoggerFactory is imported as a value - which core's Container and every application entrypoint already do. This is what makes BaseHelper resolve real loggers on the server while its own import graph stays browser-pure.\nLoggerResolver.use({ resolver: (opts) => LoggerFactory.getLogger(opts.scopes) });\n"]}
@@ -35,7 +35,7 @@ const buildInspectOptions = () => {
35
35
  /** Formats like `util.format`, but `%s` inspects to configured depth instead of Node's hard-coded `depth: 0` (no inspect option overrides that), and `%j` is projected into a JSON-safe shape first. Per-placeholder only - handing `%j` the widened STRING would emit a JSON-quoted inspect dump instead of an object. */
36
36
  const formatLogMessage = (opts) => {
37
37
  const { message, args, inspectOptions = buildInspectOptions() } = opts;
38
- const placeholders = (message.match(PLACEHOLDER_PATTERN) ?? []).filter(token => token !== '%%');
38
+ const placeholders = (message.match(PLACEHOLDER_PATTERN) ?? []).filter((token) => token !== '%%');
39
39
  const widened = args.map((arg, index) => {
40
40
  const placeholder = placeholders[index];
41
41
  const isInspectable = typeof arg === 'object' && arg !== null;
@@ -1 +1 @@
1
- {"version":3,"file":"deep-splat.js","sourceRoot":"","sources":["../../../../../src/modules/logger/formatting/deep-splat.ts"],"names":[],"mappings":";;;;;;AAAA,4CAA4D;AAC5D,0DAA6B;AAC7B,qDAAiD;AAEjD,wFAAwF;AACxF,MAAM,mBAAmB,GAAG,eAAe,CAAC;AAE5C,uQAAuQ;AACvQ,MAAM,qB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AO,CAAC,CAAC;AACrE,CAAC,CAAC;AAxDW,QAAA,gBAAgB,oBAwD3B","sourcesContent":["import { redactSecrets, toJsonSafe } from '@/common/redact';\nimport util from 'node:util';\nimport { ErrorPrettier } from './error-prettier';\n\n/** The placeholders `util.format` understands. `%%` is an escape, not a placeholder. */\nconst PLACEHOLDER_PATTERN = /%[sjdifoOc%]/g;\n\n/** How deep an object is inspected before it collapses to `[Object]`: Node's default of 2 hides nested data (e.g. wrapped `cause`), 5 reaches it while staying bounded. `APP_ENV_LOGGER_INSPECT_DEPTH` overrides with a NON-NEGATIVE number - no unlimited setting. */\nconst DEFAULT_INSPECT_DEPTH = 5;\n\nconst resolveDepth = (): number => {\n const configured = process.env.APP_ENV_LOGGER_INSPECT_DEPTH;\n\n // Not `int()`: it answers 0 for an ABSENT value, which would silently mean \"depth 0\" - the one setting that hides everything.\n if (configured === undefined || configured.trim() === '') {\n return DEFAULT_INSPECT_DEPTH;\n }\n\n const parsed = Number.parseInt(configured, 10);\n\n // A negative or unparseable value is a misconfiguration, not a request: fall back rather than hand `util.inspect` a depth it reads as \"unlimited\".\n if (Number.isNaN(parsed) || parsed < 0) {\n return DEFAULT_INSPECT_DEPTH;\n }\n\n return parsed;\n};\n\nconst buildInspectOptions = (): util.InspectOptions => {\n return {\n depth: resolveDepth(),\n maxArrayLength: null,\n maxStringLength: null,\n breakLength: Infinity,\n };\n};\n\n/** Formats like `util.format`, but `%s` inspects to configured depth instead of Node's hard-coded `depth: 0` (no inspect option overrides that), and `%j` is projected into a JSON-safe shape first. Per-placeholder only - handing `%j` the widened STRING would emit a JSON-quoted inspect dump instead of an object. */\nexport const formatLogMessage = (opts: {\n message: string;\n args: Array<unknown>;\n inspectOptions?: util.InspectOptions;\n}): string => {\n const { message, args, inspectOptions = buildInspectOptions() } = opts;\n\n const placeholders = (message.match(PLACEHOLDER_PATTERN) ?? []).filter(token => token !== '%%');\n\n const widened = args.map((arg, index) => {\n const placeholder = placeholders[index];\n const isInspectable = typeof arg === 'object' && arg !== null;\n\n if (!isInspectable) {\n return arg;\n }\n\n // `%j` runs JSON.stringify, which answers `[Circular]` for the WHOLE argument when one cycle sits anywhere inside it - a transaction handle in the payload wipes out every other field. It also has no notion of secret keys, and no depth limit of its own. Project the value first, under the same depth cap `%s` gets.\n if (placeholder === '%j') {\n return toJsonSafe({ value: arg, depth: inspectOptions.depth ?? resolveDepth() });\n }\n\n // `%o`, `%O` and arguments with NO placeholder (`util.format` appends those) are redacted but\n // left as objects, so `util.formatWithOptions` still renders them the way that placeholder\n // means. Pre-inspecting them into a string here would make `%o` print a quoted, escaped string\n // instead of an object. Only the redaction is added; the rendering is unchanged.\n //\n // Before this, `logger.info('login failed', { password })` printed the password verbatim: the\n // redactor only ever saw `%s`, while the reference docs recommend `%o` for data objects.\n //\n // Bounded like the `%s` path below, and for the same reason: an unbounded walk on a very deep\n // graph is work whose result the renderer discards, and deep enough it is a `RangeError` on a\n // call that could not throw before. `%o` renders at `depth`, so `+2` covers what is shown.\n if (placeholder === undefined || placeholder === '%o' || placeholder === '%O') {\n return redactSecrets(arg, undefined, (inspectOptions.depth ?? resolveDepth()) + 2);\n }\n\n if (placeholder !== '%s') {\n return arg;\n }\n\n // Inspecting an Error dumps every own property - a `jose` failure carries the whole JWT payload, a driver failure the whole query. Project it instead, onto its own line so it never trails off the end of the caller's sentence.\n if (arg instanceof Error) {\n return `\\n${ErrorPrettier.format({ error: arg, inspectOptions })}`;\n }\n\n // Bounded to just past what `util.inspect` will actually render. `+2`, not `+1`: at exactly\n // `depth + 1` the redactor replaces the last level with a string, and inspect then prints a\n // QUOTED `'[Object]'` instead of its own bare `[Object]`.\n return util.inspect(\n redactSecrets(arg, undefined, (inspectOptions.depth ?? resolveDepth()) + 2),\n inspectOptions,\n );\n });\n\n return util.formatWithOptions(inspectOptions, message, ...widened);\n};\n"]}
1
+ {"version":3,"file":"deep-splat.js","sourceRoot":"","sources":["../../../../../src/modules/logger/formatting/deep-splat.ts"],"names":[],"mappings":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CAAC,GAAG,CAAC,CAAC,EAC3E,cAAc,CACf,CAAC;IACJ,CAAC,CAAC,CAAC;IAEH,OAAO,mBAAI,CAAC,iBAAiB,CAAC,cAAc,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC,CAAC;AACrE,CAAC,CAAC;AAxDW,QAAA,gBAAgB,oBAwD3B","sourcesContent":["import { redactSecrets, toJsonSafe } from '@/common/redact';\nimport util from 'node:util';\nimport { ErrorPrettier } from './error-prettier';\n\n/** The placeholders `util.format` understands. `%%` is an escape, not a placeholder. */\nconst PLACEHOLDER_PATTERN = /%[sjdifoOc%]/g;\n\n/** How deep an object is inspected before it collapses to `[Object]`: Node's default of 2 hides nested data (e.g. wrapped `cause`), 5 reaches it while staying bounded. `APP_ENV_LOGGER_INSPECT_DEPTH` overrides with a NON-NEGATIVE number - no unlimited setting. */\nconst DEFAULT_INSPECT_DEPTH = 5;\n\nconst resolveDepth = (): number => {\n const configured = process.env.APP_ENV_LOGGER_INSPECT_DEPTH;\n\n // Not `int()`: it answers 0 for an ABSENT value, which would silently mean \"depth 0\" - the one setting that hides everything.\n if (configured === undefined || configured.trim() === '') {\n return DEFAULT_INSPECT_DEPTH;\n }\n\n const parsed = Number.parseInt(configured, 10);\n\n // A negative or unparseable value is a misconfiguration, not a request: fall back rather than hand `util.inspect` a depth it reads as \"unlimited\".\n if (Number.isNaN(parsed) || parsed < 0) {\n return DEFAULT_INSPECT_DEPTH;\n }\n\n return parsed;\n};\n\nconst buildInspectOptions = (): util.InspectOptions => {\n return {\n depth: resolveDepth(),\n maxArrayLength: null,\n maxStringLength: null,\n breakLength: Infinity,\n };\n};\n\n/** Formats like `util.format`, but `%s` inspects to configured depth instead of Node's hard-coded `depth: 0` (no inspect option overrides that), and `%j` is projected into a JSON-safe shape first. Per-placeholder only - handing `%j` the widened STRING would emit a JSON-quoted inspect dump instead of an object. */\nexport const formatLogMessage = (opts: {\n message: string;\n args: Array<unknown>;\n inspectOptions?: util.InspectOptions;\n}): string => {\n const { message, args, inspectOptions = buildInspectOptions() } = opts;\n\n const placeholders = (message.match(PLACEHOLDER_PATTERN) ?? []).filter((token) => token !== '%%');\n\n const widened = args.map((arg, index) => {\n const placeholder = placeholders[index];\n const isInspectable = typeof arg === 'object' && arg !== null;\n\n if (!isInspectable) {\n return arg;\n }\n\n // `%j` runs JSON.stringify, which answers `[Circular]` for the WHOLE argument when one cycle sits anywhere inside it - a transaction handle in the payload wipes out every other field. It also has no notion of secret keys, and no depth limit of its own. Project the value first, under the same depth cap `%s` gets.\n if (placeholder === '%j') {\n return toJsonSafe({ value: arg, depth: inspectOptions.depth ?? resolveDepth() });\n }\n\n // `%o`, `%O` and arguments with NO placeholder (`util.format` appends those) are redacted but\n // left as objects, so `util.formatWithOptions` still renders them the way that placeholder\n // means. Pre-inspecting them into a string here would make `%o` print a quoted, escaped string\n // instead of an object. Only the redaction is added; the rendering is unchanged.\n //\n // Before this, `logger.info('login failed', { password })` printed the password verbatim: the\n // redactor only ever saw `%s`, while the reference docs recommend `%o` for data objects.\n //\n // Bounded like the `%s` path below, and for the same reason: an unbounded walk on a very deep\n // graph is work whose result the renderer discards, and deep enough it is a `RangeError` on a\n // call that could not throw before. `%o` renders at `depth`, so `+2` covers what is shown.\n if (placeholder === undefined || placeholder === '%o' || placeholder === '%O') {\n return redactSecrets(arg, undefined, (inspectOptions.depth ?? resolveDepth()) + 2);\n }\n\n if (placeholder !== '%s') {\n return arg;\n }\n\n // Inspecting an Error dumps every own property - a `jose` failure carries the whole JWT payload, a driver failure the whole query. Project it instead, onto its own line so it never trails off the end of the caller's sentence.\n if (arg instanceof Error) {\n return `\\n${ErrorPrettier.format({ error: arg, inspectOptions })}`;\n }\n\n // Bounded to just past what `util.inspect` will actually render. `+2`, not `+1`: at exactly\n // `depth + 1` the redactor replaces the last level with a string, and inspect then prints a\n // QUOTED `'[Object]'` instead of its own bare `[Object]`.\n return util.inspect(\n redactSecrets(arg, undefined, (inspectOptions.depth ?? resolveDepth()) + 2),\n inspectOptions,\n );\n });\n\n return util.formatWithOptions(inspectOptions, message, ...widened);\n};\n"]}
@@ -85,7 +85,7 @@ class ErrorPrettier {
85
85
  if (!Array.isArray(issues) || issues.length === 0) {
86
86
  return message;
87
87
  }
88
- const lines = issues.slice(0, this.MAX_ZOD_ISSUES).map(issue => {
88
+ const lines = issues.slice(0, this.MAX_ZOD_ISSUES).map((issue) => {
89
89
  const entry = issue;
90
90
  const path = Array.isArray(entry.path) && entry.path.length > 0 ? entry.path.join('.') : '(root)';
91
91
  return `${path}: ${entry.message ?? entry.code ?? 'invalid'}`;
@@ -163,7 +163,7 @@ class ErrorPrettier {
163
163
  }
164
164
  // A protocol client reports one member per thing that failed; the wrapper carries only a generic sentence.
165
165
  if (Array.isArray(source.errors) && source.errors.length > 0 && depthLeft > 0) {
166
- const members = source.errors.slice(0, this.MAX_AGGREGATED_ERRORS).map(member => this.summarizeNode({
166
+ const members = source.errors.slice(0, this.MAX_AGGREGATED_ERRORS).map((member) => this.summarizeNode({
167
167
  value: member,
168
168
  depthLeft: depthLeft - 1,
169
169
  seen,
@@ -274,7 +274,7 @@ class ErrorPrettier {
274
274
  }
275
275
  // An ARRAY, not the newline-joined string `text` prints: a monitor can count and slice frames.
276
276
  if (summary.stack !== undefined) {
277
- payload.stack = summary.stack.split('\n').map(frame => frame.trim());
277
+ payload.stack = summary.stack.split('\n').map((frame) => frame.trim());
278
278
  }
279
279
  return this.safeStringify(payload);
280
280
  }
@@ -320,7 +320,7 @@ class ErrorPrettier {
320
320
  if (summary.stack !== undefined) {
321
321
  lines.push(`stack:\n${summary.stack}`);
322
322
  }
323
- return lines.map(line => `- ${line}`).join('\n');
323
+ return lines.map((line) => `- ${line}`).join('\n');
324
324
  }
325
325
  /** Renders {@link summarize}. `text` returns a block whose newlines survive `%s`; `json` returns one line. */
326
326
  static format(opts) {