@naturalcycles/nodejs-lib 12.45.0 → 12.45.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.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,10 @@
1
+ ## [12.45.1](https://github.com/NaturalCycles/nodejs-lib/compare/v12.45.0...v12.45.1) (2021-10-25)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * make JoiValidationError.annotation non-enumerable ([9337fd3](https://github.com/NaturalCycles/nodejs-lib/commit/9337fd3e1a60deb0d9e91b17cf5e7b42f72b5459))
7
+
1
8
  # [12.45.0](https://github.com/NaturalCycles/nodejs-lib/compare/v12.44.0...v12.45.0) (2021-10-22)
2
9
 
3
10
 
@@ -1,3 +1,4 @@
1
+ import { AnyObject } from '@naturalcycles/js-lib';
1
2
  export interface TableDiffOptions {
2
3
  /**
3
4
  * @default false
@@ -29,4 +30,4 @@ export interface TableDiffOptions {
29
30
  *
30
31
  * Function is located in nodejs-lib (not js-lib), because it's planned to improve in the future and add e.g colors (via chalk).
31
32
  */
32
- export declare function tableDiff(a: Record<string, any>, b: Record<string, any>, opt?: TableDiffOptions): void;
33
+ export declare function tableDiff(a: AnyObject, b: AnyObject, opt?: TableDiffOptions): void;
@@ -1,3 +1,4 @@
1
+ import { AnyObject } from '@naturalcycles/js-lib';
1
2
  import type { Options } from 'got';
2
3
  export interface GetGotOptions extends Options {
3
4
  /**
@@ -33,7 +34,7 @@ export interface GetGotOptions extends Options {
33
34
  */
34
35
  maxResponseLength?: number;
35
36
  }
36
- export interface GotRequestContext extends Record<string, any> {
37
+ export interface GotRequestContext extends AnyObject {
37
38
  /**
38
39
  * Millisecond-timestamp of when the request was started. To be able to count "time spent".
39
40
  */
@@ -24,5 +24,5 @@ export interface TransformJsonParseOptions {
24
24
  * consumeYourStream...
25
25
  * [)
26
26
  */
27
- export declare function transformJsonParse<OUT = Record<string, any>>(opt?: TransformJsonParseOptions): TransformTyped<string | Buffer, OUT>;
27
+ export declare function transformJsonParse<OUT = any>(opt?: TransformJsonParseOptions): TransformTyped<string | Buffer, OUT>;
28
28
  export declare const bufferReviver: Reviver;
@@ -7,4 +7,4 @@ export interface TransformBufferOptions extends TransformOptions {
7
7
  *
8
8
  * @default batchSize is 10
9
9
  */
10
- export declare function transformBuffer<IN = Record<string, any>>(opt: TransformBufferOptions): TransformTyped<IN, IN[]>;
10
+ export declare function transformBuffer<IN = any>(opt: TransformBufferOptions): TransformTyped<IN, IN[]>;
@@ -1,3 +1,4 @@
1
+ import { AnyObject } from '@naturalcycles/js-lib';
1
2
  import { TransformOptions, TransformTyped } from '../stream.model';
2
3
  export interface TransformLogProgressOptions<IN = any> extends TransformOptions {
3
4
  /**
@@ -73,7 +74,7 @@ export interface TransformLogProgressOptions<IN = any> extends TransformOptions
73
74
  *
74
75
  * chunk is undefined for "final" stats, otherwise is defined.
75
76
  */
76
- extra?: (chunk: IN | undefined, index: number) => Record<string, any>;
77
+ extra?: (chunk: IN | undefined, index: number) => AnyObject;
77
78
  }
78
79
  /**
79
80
  * Pass-through transform that optionally logs progress.
@@ -1,3 +1,4 @@
1
+ import { AnyObject } from '@naturalcycles/js-lib';
1
2
  import { TransformTyped } from '../../stream.model';
2
3
  export interface TransformMultiThreadedOptions {
3
4
  /**
@@ -19,7 +20,7 @@ export interface TransformMultiThreadedOptions {
19
20
  /**
20
21
  * Passed to the Worker as `workerData` property (initial data).
21
22
  */
22
- workerData?: Record<string, any>;
23
+ workerData?: AnyObject;
23
24
  }
24
25
  /**
25
26
  * Spawns a pool of Workers (threads).
@@ -17,6 +17,9 @@ export interface JoiValidationErrorData extends ErrorData {
17
17
  /**
18
18
  * Error "annotation" is stripped in Error.message.
19
19
  * This field contains the "full" annotation.
20
+ *
21
+ * This field is non-enumerable, won't be printed or included in JSON by default,
22
+ * but still accessible programmatically (via `err.data.annotation`) when needed!
20
23
  */
21
24
  annotation?: string;
22
25
  }
@@ -122,10 +122,16 @@ function createError(value, err, objectName) {
122
122
  tokens.push(annotation);
123
123
  }
124
124
  const msg = tokens.join('\n');
125
- return new joi_validation_error_1.JoiValidationError(msg, {
125
+ const data = {
126
126
  joiValidationErrorItems: err.details,
127
127
  ...(objectName && { joiValidationObjectName: objectName }),
128
128
  ...(objectId && { joiValidationObjectId: objectId }),
129
- annotation,
129
+ };
130
+ // Make annotation non-enumerable, to not get it automatically printed,
131
+ // but still accessible
132
+ Object.defineProperty(data, 'annotation', {
133
+ enumerable: false,
134
+ value: annotation,
130
135
  });
136
+ return new joi_validation_error_1.JoiValidationError(msg, data);
131
137
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@naturalcycles/nodejs-lib",
3
- "version": "12.45.0",
3
+ "version": "12.45.1",
4
4
  "scripts": {
5
5
  "prepare": "husky install",
6
6
  "docs-serve": "vuepress dev docs",
@@ -1,4 +1,4 @@
1
- import { StringMap, _truncate } from '@naturalcycles/js-lib'
1
+ import { StringMap, _truncate, AnyObject } from '@naturalcycles/js-lib'
2
2
 
3
3
  export interface TableDiffOptions {
4
4
  /**
@@ -35,11 +35,7 @@ export interface TableDiffOptions {
35
35
  *
36
36
  * Function is located in nodejs-lib (not js-lib), because it's planned to improve in the future and add e.g colors (via chalk).
37
37
  */
38
- export function tableDiff(
39
- a: Record<string, any>,
40
- b: Record<string, any>,
41
- opt: TableDiffOptions = {},
42
- ): void {
38
+ export function tableDiff(a: AnyObject, b: AnyObject, opt: TableDiffOptions = {}): void {
43
39
  const { maxFieldLen, aTitle = 'a', bTitle = 'b' } = opt
44
40
  const diff: StringMap<any> = {}
45
41
 
@@ -1,3 +1,4 @@
1
+ import { AnyObject } from '@naturalcycles/js-lib'
1
2
  import type { Options } from 'got'
2
3
 
3
4
  export interface GetGotOptions extends Options {
@@ -40,7 +41,7 @@ export interface GetGotOptions extends Options {
40
41
  maxResponseLength?: number
41
42
  }
42
43
 
43
- export interface GotRequestContext extends Record<string, any> {
44
+ export interface GotRequestContext extends AnyObject {
44
45
  /**
45
46
  * Millisecond-timestamp of when the request was started. To be able to count "time spent".
46
47
  */
@@ -27,7 +27,7 @@ export interface TransformJsonParseOptions {
27
27
  * consumeYourStream...
28
28
  * [)
29
29
  */
30
- export function transformJsonParse<OUT = Record<string, any>>(
30
+ export function transformJsonParse<OUT = any>(
31
31
  opt: TransformJsonParseOptions = {},
32
32
  ): TransformTyped<string | Buffer, OUT> {
33
33
  const { strict = true, reviver } = opt
@@ -10,9 +10,7 @@ export interface TransformBufferOptions extends TransformOptions {
10
10
  *
11
11
  * @default batchSize is 10
12
12
  */
13
- export function transformBuffer<IN = Record<string, any>>(
14
- opt: TransformBufferOptions,
15
- ): TransformTyped<IN, IN[]> {
13
+ export function transformBuffer<IN = any>(opt: TransformBufferOptions): TransformTyped<IN, IN[]> {
16
14
  const { batchSize } = opt
17
15
 
18
16
  let buf: IN[] = []
@@ -1,6 +1,6 @@
1
1
  import { Transform } from 'stream'
2
2
  import { inspect, InspectOptions } from 'util'
3
- import { SimpleMovingAverage, _mb, _since } from '@naturalcycles/js-lib'
3
+ import { SimpleMovingAverage, _mb, _since, AnyObject } from '@naturalcycles/js-lib'
4
4
  import { dayjs } from '@naturalcycles/time-lib'
5
5
  import { boldWhite, dimGrey, white, yellow } from '../../colors'
6
6
  import { hasColors } from '../../colors/colors'
@@ -91,7 +91,7 @@ export interface TransformLogProgressOptions<IN = any> extends TransformOptions
91
91
  *
92
92
  * chunk is undefined for "final" stats, otherwise is defined.
93
93
  */
94
- extra?: (chunk: IN | undefined, index: number) => Record<string, any>
94
+ extra?: (chunk: IN | undefined, index: number) => AnyObject
95
95
  }
96
96
 
97
97
  const inspectOpt: InspectOptions = {
@@ -1,5 +1,5 @@
1
1
  import { Worker } from 'worker_threads'
2
- import { DeferredPromise, pDefer, _range } from '@naturalcycles/js-lib'
2
+ import { DeferredPromise, pDefer, _range, AnyObject } from '@naturalcycles/js-lib'
3
3
  import through2Concurrent = require('through2-concurrent')
4
4
  import { TransformTyped } from '../../stream.model'
5
5
  import { WorkerInput, WorkerOutput } from './transformMultiThreaded.model'
@@ -30,7 +30,7 @@ export interface TransformMultiThreadedOptions {
30
30
  /**
31
31
  * Passed to the Worker as `workerData` property (initial data).
32
32
  */
33
- workerData?: Record<string, any>
33
+ workerData?: AnyObject
34
34
  }
35
35
 
36
36
  const workerProxyFilePath = `${__dirname}/workerClassProxy.js`
@@ -18,6 +18,9 @@ export interface JoiValidationErrorData extends ErrorData {
18
18
  /**
19
19
  * Error "annotation" is stripped in Error.message.
20
20
  * This field contains the "full" annotation.
21
+ *
22
+ * This field is non-enumerable, won't be printed or included in JSON by default,
23
+ * but still accessible programmatically (via `err.data.annotation`) when needed!
21
24
  */
22
25
  annotation?: string
23
26
  }
@@ -9,7 +9,7 @@
9
9
  import { _hb, _isObject, _truncateMiddle } from '@naturalcycles/js-lib'
10
10
  import { ValidationError, ValidationOptions } from 'joi'
11
11
  import { AnySchemaTyped } from './joi.model'
12
- import { JoiValidationError } from './joi.validation.error'
12
+ import { JoiValidationError, JoiValidationErrorData } from './joi.validation.error'
13
13
 
14
14
  // todo: consider replacing with Tuple of [error, value]
15
15
  export interface JoiValidationResult<T = any> {
@@ -163,10 +163,18 @@ function createError(value: any, err: ValidationError, objectName?: string): Joi
163
163
 
164
164
  const msg = tokens.join('\n')
165
165
 
166
- return new JoiValidationError(msg, {
166
+ const data: JoiValidationErrorData = {
167
167
  joiValidationErrorItems: err.details,
168
168
  ...(objectName && { joiValidationObjectName: objectName }),
169
169
  ...(objectId && { joiValidationObjectId: objectId }),
170
- annotation,
170
+ }
171
+
172
+ // Make annotation non-enumerable, to not get it automatically printed,
173
+ // but still accessible
174
+ Object.defineProperty(data, 'annotation', {
175
+ enumerable: false,
176
+ value: annotation,
171
177
  })
178
+
179
+ return new JoiValidationError(msg, data)
172
180
  }