@naturalcycles/js-lib 15.100.0 → 15.102.0

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 (57) hide show
  1. package/dist/abort.d.ts +0 -8
  2. package/dist/abort.js +2 -19
  3. package/dist/array/array.util.d.ts +1 -3
  4. package/dist/array/array.util.js +1 -3
  5. package/dist/array/sort.js +1 -1
  6. package/dist/array/sortedSet.d.ts +1 -1
  7. package/dist/array/sortedSet.js +1 -1
  8. package/dist/asyncManager.js +5 -4
  9. package/dist/browser/analytics.util.js +3 -2
  10. package/dist/browser/topbar.js +1 -1
  11. package/dist/datetime/localDate.js +10 -5
  12. package/dist/datetime/localTime.d.ts +4 -0
  13. package/dist/datetime/localTime.js +17 -8
  14. package/dist/datetime/time.util.d.ts +18 -1
  15. package/dist/datetime/time.util.js +28 -2
  16. package/dist/decorators/createPromiseDecorator.js +2 -1
  17. package/dist/decorators/debounce.js +7 -6
  18. package/dist/decorators/logMethod.decorator.js +3 -3
  19. package/dist/enum.util.js +1 -0
  20. package/dist/error/tryCatch.js +2 -2
  21. package/dist/http/fetcher.js +13 -13
  22. package/dist/index.d.ts +1 -1
  23. package/dist/index.js +0 -1
  24. package/dist/object/deepEquals.js +2 -0
  25. package/dist/object/keySortedMap.js +1 -1
  26. package/dist/object/lazyKeySortedMap.js +1 -1
  27. package/dist/object/object.util.js +2 -2
  28. package/dist/promise/pGradualQueue.js +3 -2
  29. package/dist/promise/pRetry.js +2 -2
  30. package/dist/semver.js +10 -5
  31. package/dist/string/stringify.js +1 -2
  32. package/package.json +4 -2
  33. package/src/abort.ts +2 -21
  34. package/src/array/array.util.ts +1 -3
  35. package/src/array/sort.ts +1 -1
  36. package/src/array/sortedSet.ts +1 -1
  37. package/src/asyncManager.ts +5 -4
  38. package/src/browser/analytics.util.ts +3 -2
  39. package/src/browser/topbar.ts +1 -1
  40. package/src/datetime/localDate.ts +12 -6
  41. package/src/datetime/localTime.ts +19 -9
  42. package/src/datetime/time.util.ts +32 -3
  43. package/src/decorators/createPromiseDecorator.ts +2 -1
  44. package/src/decorators/debounce.ts +7 -6
  45. package/src/decorators/logMethod.decorator.ts +3 -3
  46. package/src/enum.util.ts +1 -0
  47. package/src/error/tryCatch.ts +3 -3
  48. package/src/http/fetcher.ts +15 -20
  49. package/src/index.ts +1 -1
  50. package/src/object/deepEquals.ts +2 -0
  51. package/src/object/keySortedMap.ts +1 -1
  52. package/src/object/lazyKeySortedMap.ts +1 -1
  53. package/src/object/object.util.ts +2 -2
  54. package/src/promise/pGradualQueue.ts +3 -2
  55. package/src/promise/pRetry.ts +3 -3
  56. package/src/semver.ts +11 -7
  57. package/src/string/stringify.ts +2 -4
@@ -1,3 +1,4 @@
1
+ import { nowUnixMillis } from '../datetime/time.util.js'
1
2
  import { ErrorMode } from '../error/errorMode.js'
2
3
  import { createCommonLoggerAtLevel } from '../log/commonLogger.js'
3
4
  import type { CommonLogger, CommonLogLevel } from '../log/commonLogger.js'
@@ -73,7 +74,7 @@ export class PGradualQueue {
73
74
  // Fast-path: warmup complete
74
75
  if (this.warmupComplete) return this.cfg.concurrency
75
76
 
76
- const elapsed = Date.now() - this.startTime
77
+ const elapsed = nowUnixMillis() - this.startTime
77
78
  if (elapsed >= this.warmupMs) {
78
79
  this.warmupComplete = true
79
80
  this.logger.debug('warmup complete')
@@ -92,7 +93,7 @@ export class PGradualQueue {
92
93
  async push<R>(fn: AsyncFunction<R>): Promise<R> {
93
94
  // Initialize start time on first push
94
95
  if (this.startTime === 0) {
95
- this.startTime = Date.now()
96
+ this.startTime = nowUnixMillis()
96
97
  }
97
98
 
98
99
  const job: PGradualQueueJob<R> = { fn, defer: pDefer<R>() }
@@ -1,9 +1,9 @@
1
- import { _since } from '../datetime/time.util.js'
1
+ import { _since, nowUnixMillis } from '../datetime/time.util.js'
2
2
  import type { ErrorData } from '../error/error.model.js'
3
3
  import { _errorDataAppend } from '../error/error.util.js'
4
4
  import { consoleLogger } from '../log/commonLogger.js'
5
5
  import type { CommonLogger } from '../log/commonLogger.js'
6
- import type { AnyAsyncFunction, UnixTimestampMillis } from '../types.js'
6
+ import type { AnyAsyncFunction } from '../types.js'
7
7
  import { pDelay } from './pDelay.js'
8
8
  import { pTimeout } from './pTimeout.js'
9
9
 
@@ -141,7 +141,7 @@ export async function pRetry<T>(
141
141
  let attempt = 0
142
142
 
143
143
  while (true) {
144
- const started = Date.now() as UnixTimestampMillis
144
+ const started = nowUnixMillis()
145
145
 
146
146
  try {
147
147
  attempt++
package/src/semver.ts CHANGED
@@ -147,13 +147,17 @@ interface SemverFn extends SemverFactory {
147
147
  (input: SemverInput): Semver
148
148
  }
149
149
 
150
- const semverFactory = new SemverFactory()
151
-
152
- export const semver2 = semverFactory.fromInput.bind(semverFactory) as SemverFn
153
-
154
- // The line below is the blackest of black magic I have ever written in 2024.
155
- // And probably 2023 as well.
156
- Object.setPrototypeOf(semver2, semverFactory)
150
+ // Built inside a function, so the whole construct can be marked pure and tree-shaken (see treeshake.test.ts)
151
+ export const semver2 = /* @__PURE__ */ createSemverFn()
152
+
153
+ function createSemverFn(): SemverFn {
154
+ const semverFactory = new SemverFactory()
155
+ const fn = semverFactory.fromInput.bind(semverFactory) as SemverFn
156
+ // The line below is the blackest of black magic I have ever written in 2024.
157
+ // And probably 2023 as well.
158
+ Object.setPrototypeOf(fn, semverFactory)
159
+ return fn
160
+ }
157
161
 
158
162
  /**
159
163
  * Returns 1 if a > b
@@ -1,14 +1,12 @@
1
+ import type { ErrorLike } from '../error/error.model.js'
1
2
  // oxlint-disable-next-line import/no-cycle -- intentional cycle
2
3
  import { _isBackendErrorResponseObject, _isErrorLike, _isErrorObject } from '../error/error.util.js'
3
- import type { ErrorLike } from '../error/index.js'
4
4
  import type { Reviver } from '../types.js'
5
5
  // oxlint-disable-next-line import/no-cycle -- intentional cycle
6
6
  import { _jsonParseIfPossible } from './json.util.js'
7
7
  import { _safeJsonStringify } from './safeJsonStringify.js'
8
8
  import { _truncateMiddle } from './string.util.js'
9
9
 
10
- const supportsAggregateError = typeof globalThis.AggregateError === 'function'
11
-
12
10
  let globalStringifyFunction: JsonStringifyFunction = _safeJsonStringify
13
11
 
14
12
  /**
@@ -184,7 +182,7 @@ function stringifyErrorLike(obj: Error | ErrorLike, opt: StringifyOptions): stri
184
182
  s = [s, ...obj.stack.split('\n').slice(sLines)].join('\n')
185
183
  }
186
184
 
187
- if (supportsAggregateError && obj instanceof AggregateError && obj.errors.length) {
185
+ if (obj instanceof AggregateError && obj.errors.length) {
188
186
  s = [
189
187
  s,
190
188
  `${obj.errors.length} error(s):`,