@naturalcycles/nodejs-lib 12.68.1 → 12.70.1

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.
@@ -2,7 +2,6 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.slackDefaultMessagePrefixHook = exports.SlackService = void 0;
4
4
  const js_lib_1 = require("@naturalcycles/js-lib");
5
- const time_lib_1 = require("@naturalcycles/time-lib");
6
5
  const got_1 = require("got");
7
6
  const __1 = require("..");
8
7
  const GAE = !!process.env['GAE_INSTANCE'];
@@ -128,7 +127,7 @@ class SlackService {
128
127
  }
129
128
  exports.SlackService = SlackService;
130
129
  function slackDefaultMessagePrefixHook(msg) {
131
- const tokens = [(0, time_lib_1.dayjs)().toPretty()];
130
+ const tokens = [(0, js_lib_1.localTime)().toPretty()];
132
131
  const { ctx } = msg;
133
132
  // AppEngine-specific decoration
134
133
  if (GAE && ctx && typeof ctx === 'object' && typeof ctx.header === 'function') {
@@ -4,7 +4,6 @@ exports.transformLogProgress = void 0;
4
4
  const stream_1 = require("stream");
5
5
  const util_1 = require("util");
6
6
  const js_lib_1 = require("@naturalcycles/js-lib");
7
- const time_lib_1 = require("@naturalcycles/time-lib");
8
7
  const colors_1 = require("../../colors");
9
8
  const colors_2 = require("../../colors/colors");
10
9
  const sizeStack_1 = require("../sizeStack");
@@ -94,7 +93,7 @@ function transformLogProgress(opt = {}) {
94
93
  if (perHour > 900) {
95
94
  perHour = Math.round(perHour / 1000) + 'K';
96
95
  }
97
- logger.log(`${(0, colors_1.dimGrey)((0, time_lib_1.dayjs)().toPretty())} ${(0, colors_1.white)(metric)} took ${(0, colors_1.yellow)((0, js_lib_1._since)(started))} so far to process ${(0, colors_1.yellow)(batchedProgress)} rows, ~${(0, colors_1.yellow)(perHour)}/hour`);
96
+ logger.log(`${(0, colors_1.dimGrey)((0, js_lib_1.localTime)().toPretty())} ${(0, colors_1.white)(metric)} took ${(0, colors_1.yellow)((0, js_lib_1._since)(started))} so far to process ${(0, colors_1.yellow)(batchedProgress)} rows, ~${(0, colors_1.yellow)(perHour)}/hour`);
98
97
  }
99
98
  else if (final) {
100
99
  logger.log(`${(0, colors_1.boldWhite)(metric)} took ${(0, colors_1.yellow)((0, js_lib_1._since)(started))} to process ${(0, colors_1.yellow)(batchedProgress)} rows with total RPS of ${(0, colors_1.yellow)(rpsTotal)}`);
@@ -29,7 +29,7 @@ export interface TransformMapOptions<IN = any, OUT = IN> {
29
29
  * If defined - will be called on every error happening in the stream.
30
30
  * Called BEFORE observable will emit error (unless skipErrors is set to true).
31
31
  */
32
- onError?: (err: unknown, input: IN) => any;
32
+ onError?: (err: Error, input: IN) => any;
33
33
  /**
34
34
  * Progress metric
35
35
  *
@@ -67,7 +67,7 @@ function transformMap(mapper, opt = {}) {
67
67
  logErrorStats();
68
68
  if (onError) {
69
69
  try {
70
- onError(err, chunk);
70
+ onError((0, js_lib_1._anyToError)(err), chunk);
71
71
  }
72
72
  catch { }
73
73
  }
@@ -27,7 +27,7 @@ export interface TransformMapSyncOptions<IN = any, OUT = IN> {
27
27
  * If defined - will be called on every error happening in the stream.
28
28
  * Called BEFORE observable will emit error (unless skipErrors is set to true).
29
29
  */
30
- onError?: (err: unknown, input: IN) => any;
30
+ onError?: (err: Error, input: IN) => any;
31
31
  /**
32
32
  * Progress metric
33
33
  *
@@ -50,7 +50,7 @@ function transformMapSync(mapper, opt = {}) {
50
50
  logErrorStats();
51
51
  if (onError) {
52
52
  try {
53
- onError(err, chunk);
53
+ onError((0, js_lib_1._anyToError)(err), chunk);
54
54
  }
55
55
  catch { }
56
56
  }
@@ -1,5 +1,5 @@
1
1
  import { MemoCache } from '@naturalcycles/js-lib';
2
- import LRUCache = require('lru-cache');
2
+ import * as LRUCache from 'lru-cache';
3
3
  export declare type LRUMemoCacheOptions<KEY, VALUE> = Partial<LRUCache.Options<KEY, VALUE>>;
4
4
  /**
5
5
  * @example
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.stringExtensions = void 0;
4
- const time_lib_1 = require("@naturalcycles/time-lib");
4
+ const js_lib_1 = require("@naturalcycles/js-lib");
5
5
  function stringExtensions(joi) {
6
6
  return {
7
7
  type: 'string',
@@ -41,10 +41,10 @@ function stringExtensions(joi) {
41
41
  let { min, max } = args;
42
42
  // Today allows +-14 hours gap to account for different timezones
43
43
  if (max === 'today') {
44
- max = (0, time_lib_1.dayjs)().add(14, 'hour').toISODate();
44
+ max = (0, js_lib_1.localTime)().add(14, 'hour').toISODate();
45
45
  }
46
46
  if (min === 'today') {
47
- min = (0, time_lib_1.dayjs)().subtract(14, 'hour').toISODate();
47
+ min = (0, js_lib_1.localTime)().subtract(14, 'hour').toISODate();
48
48
  }
49
49
  // console.log('min/max', min, max)
50
50
  const m = /^(\d{4})-(\d{2})-(\d{2})$/.exec(v);
@@ -57,7 +57,7 @@ function stringExtensions(joi) {
57
57
  else if (max && v > max) {
58
58
  err = 'string.dateStringMax';
59
59
  }
60
- else if (!(0, time_lib_1.dayjs)(v).isValid()) {
60
+ else if (!js_lib_1.LocalDate.isValid(v)) {
61
61
  // todo: replace with another regex (from ajv-validators) for speed
62
62
  err = 'string.dateStringCalendarAccuracy';
63
63
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@naturalcycles/nodejs-lib",
3
- "version": "12.68.1",
3
+ "version": "12.70.1",
4
4
  "scripts": {
5
5
  "prepare": "husky install",
6
6
  "docs-serve": "vuepress dev docs",
@@ -15,8 +15,6 @@
15
15
  },
16
16
  "dependencies": {
17
17
  "@naturalcycles/js-lib": "^14.0.0",
18
- "@naturalcycles/time-lib": "^3.0.1",
19
- "@types/lru-cache": "^7.4.0",
20
18
  "@types/through2-concurrent": "^2.0.0",
21
19
  "ajv": "^8.6.2",
22
20
  "ajv-formats": "^2.1.0",
@@ -43,7 +41,7 @@
43
41
  "@naturalcycles/dev-lib": "^12.0.0",
44
42
  "@types/node": "^17.0.0",
45
43
  "@types/yargs": "^16.0.0",
46
- "jest": "^27.0.1",
44
+ "jest": "^28.0.3",
47
45
  "nock": "^13.0.2",
48
46
  "patch-package": "^6.2.1",
49
47
  "prettier": "^2.0.0",
@@ -4,9 +4,9 @@ import {
4
4
  CommonLogger,
5
5
  commonLoggerMinLevel,
6
6
  CommonLogLevel,
7
+ localTime,
7
8
  PQueue,
8
9
  } from '@naturalcycles/js-lib'
9
- import { dayjs } from '@naturalcycles/time-lib'
10
10
  import got from 'got'
11
11
  import { inspectAny, InspectAnyOptions } from '..'
12
12
  import {
@@ -172,7 +172,7 @@ export class SlackService<CTX = any> {
172
172
  }
173
173
 
174
174
  export function slackDefaultMessagePrefixHook(msg: SlackMessage): string[] {
175
- const tokens = [dayjs().toPretty()]
175
+ const tokens = [localTime().toPretty()]
176
176
  const { ctx } = msg
177
177
 
178
178
  // AppEngine-specific decoration
@@ -1,7 +1,13 @@
1
1
  import { Transform } from 'stream'
2
2
  import { inspect, InspectOptions } from 'util'
3
- import { SimpleMovingAverage, _mb, _since, AnyObject, CommonLogger } from '@naturalcycles/js-lib'
4
- import { dayjs } from '@naturalcycles/time-lib'
3
+ import {
4
+ SimpleMovingAverage,
5
+ _mb,
6
+ _since,
7
+ AnyObject,
8
+ CommonLogger,
9
+ localTime,
10
+ } from '@naturalcycles/js-lib'
5
11
  import { boldWhite, dimGrey, white, yellow } from '../../colors'
6
12
  import { hasColors } from '../../colors/colors'
7
13
  import { SizeStack } from '../sizeStack'
@@ -255,7 +261,7 @@ export function transformLogProgress<IN = any>(
255
261
  }
256
262
 
257
263
  logger.log(
258
- `${dimGrey(dayjs().toPretty())} ${white(metric)} took ${yellow(
264
+ `${dimGrey(localTime().toPretty())} ${white(metric)} took ${yellow(
259
265
  _since(started),
260
266
  )} so far to process ${yellow(batchedProgress)} rows, ~${yellow(perHour)}/hour`,
261
267
  )
@@ -1,4 +1,5 @@
1
1
  import {
2
+ _anyToError,
2
3
  AbortableAsyncMapper,
3
4
  AggregatedError,
4
5
  AsyncPredicate,
@@ -47,7 +48,7 @@ export interface TransformMapOptions<IN = any, OUT = IN> {
47
48
  * If defined - will be called on every error happening in the stream.
48
49
  * Called BEFORE observable will emit error (unless skipErrors is set to true).
49
50
  */
50
- onError?: (err: unknown, input: IN) => any
51
+ onError?: (err: Error, input: IN) => any
51
52
 
52
53
  /**
53
54
  * Progress metric
@@ -144,7 +145,7 @@ export function transformMap<IN = any, OUT = IN>(
144
145
 
145
146
  if (onError) {
146
147
  try {
147
- onError(err, chunk)
148
+ onError(_anyToError(err), chunk)
148
149
  } catch {}
149
150
  }
150
151
 
@@ -1,4 +1,5 @@
1
1
  import {
2
+ _anyToError,
2
3
  AggregatedError,
3
4
  CommonLogger,
4
5
  END,
@@ -42,7 +43,7 @@ export interface TransformMapSyncOptions<IN = any, OUT = IN> {
42
43
  * If defined - will be called on every error happening in the stream.
43
44
  * Called BEFORE observable will emit error (unless skipErrors is set to true).
44
45
  */
45
- onError?: (err: unknown, input: IN) => any
46
+ onError?: (err: Error, input: IN) => any
46
47
 
47
48
  /**
48
49
  * Progress metric
@@ -116,7 +117,7 @@ export function transformMapSync<IN = any, OUT = IN>(
116
117
 
117
118
  if (onError) {
118
119
  try {
119
- onError(err, chunk)
120
+ onError(_anyToError(err), chunk)
120
121
  } catch {}
121
122
  }
122
123
 
@@ -1,5 +1,5 @@
1
1
  import { MemoCache } from '@naturalcycles/js-lib'
2
- import LRUCache = require('lru-cache')
2
+ import * as LRUCache from 'lru-cache'
3
3
 
4
4
  // Partial, to be able to provide default `max`
5
5
  export type LRUMemoCacheOptions<KEY, VALUE> = Partial<LRUCache.Options<KEY, VALUE>>
@@ -1,4 +1,4 @@
1
- import { dayjs } from '@naturalcycles/time-lib'
1
+ import { LocalDate, localTime } from '@naturalcycles/js-lib'
2
2
  import { Extension, StringSchema } from 'joi'
3
3
  import * as Joi from 'joi'
4
4
  import { AnySchemaTyped } from './joi.model'
@@ -53,10 +53,10 @@ export function stringExtensions(joi: typeof Joi): Extension {
53
53
 
54
54
  // Today allows +-14 hours gap to account for different timezones
55
55
  if (max === 'today') {
56
- max = dayjs().add(14, 'hour').toISODate()
56
+ max = localTime().add(14, 'hour').toISODate()
57
57
  }
58
58
  if (min === 'today') {
59
- min = dayjs().subtract(14, 'hour').toISODate()
59
+ min = localTime().subtract(14, 'hour').toISODate()
60
60
  }
61
61
  // console.log('min/max', min, max)
62
62
 
@@ -67,7 +67,7 @@ export function stringExtensions(joi: typeof Joi): Extension {
67
67
  err = 'string.dateStringMin'
68
68
  } else if (max && v > max) {
69
69
  err = 'string.dateStringMax'
70
- } else if (!dayjs(v).isValid()) {
70
+ } else if (!LocalDate.isValid(v)) {
71
71
  // todo: replace with another regex (from ajv-validators) for speed
72
72
  err = 'string.dateStringCalendarAccuracy'
73
73
  }