@naturalcycles/nodejs-lib 12.41.0 → 12.42.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.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,10 @@
1
+ # [12.42.0](https://github.com/NaturalCycles/nodejs-lib/compare/v12.41.0...v12.42.0) (2021-10-19)
2
+
3
+
4
+ ### Features
5
+
6
+ * JoiValidationError to include full `annotation` ([c17756e](https://github.com/NaturalCycles/nodejs-lib/commit/c17756e1f8760987e62f6bee35f72fe7449b5671))
7
+
1
8
  # [12.41.0](https://github.com/NaturalCycles/nodejs-lib/compare/v12.40.0...v12.41.0) (2021-10-18)
2
9
 
3
10
 
@@ -14,6 +14,11 @@ export interface JoiValidationErrorData extends ErrorData {
14
14
  joiValidationErrorItems: ValidationErrorItem[];
15
15
  joiValidationObjectName?: string;
16
16
  joiValidationObjectId?: string;
17
+ /**
18
+ * Error "annotation" is stripped in Error.message.
19
+ * This field contains the "full" annotation.
20
+ */
21
+ annotation?: string;
17
22
  }
18
23
  export declare class JoiValidationError extends AppError<JoiValidationErrorData> {
19
24
  constructor(message: string, data: JoiValidationErrorData);
@@ -110,9 +110,9 @@ function createError(value, err, objectName) {
110
110
  tokens.push('Invalid ' + [objectName, objectId].filter(Boolean).join('.'));
111
111
  }
112
112
  const annotation = err.annotate(stripColors);
113
- if (annotation.length > 2000) {
113
+ if (annotation.length > 4000) {
114
114
  // Annotation message is too big and will be replaced by stringified `error.details` instead
115
- tokens.push(annotation.slice(0, 2000), `... ${Math.ceil(annotation.length / 1024)} KB message truncated`);
115
+ tokens.push((0, js_lib_1._truncateMiddle)(annotation, 4000, `\n... ${(0, js_lib_1._hb)(annotation.length)} message truncated ...\n`));
116
116
  // Up to 5 `details`
117
117
  tokens.push(...err.details.slice(0, 5).map(i => `${i.message} @ .${i.path.join('.')}`));
118
118
  if (err.details.length > 5)
@@ -126,5 +126,6 @@ function createError(value, err, objectName) {
126
126
  joiValidationErrorItems: err.details,
127
127
  ...(objectName && { joiValidationObjectName: objectName }),
128
128
  ...(objectId && { joiValidationObjectId: objectId }),
129
+ annotation,
129
130
  });
130
131
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@naturalcycles/nodejs-lib",
3
- "version": "12.41.0",
3
+ "version": "12.42.0",
4
4
  "scripts": {
5
5
  "prepare": "husky install",
6
6
  "docs-serve": "vuepress dev docs",
@@ -15,6 +15,11 @@ export interface JoiValidationErrorData extends ErrorData {
15
15
  joiValidationErrorItems: ValidationErrorItem[]
16
16
  joiValidationObjectName?: string
17
17
  joiValidationObjectId?: string
18
+ /**
19
+ * Error "annotation" is stripped in Error.message.
20
+ * This field contains the "full" annotation.
21
+ */
22
+ annotation?: string
18
23
  }
19
24
 
20
25
  export class JoiValidationError extends AppError<JoiValidationErrorData> {
@@ -6,7 +6,7 @@
6
6
  * "Converts" mean e.g trims all strings from leading/trailing spaces.
7
7
  */
8
8
 
9
- import { _isObject } from '@naturalcycles/js-lib'
9
+ import { _hb, _isObject, _truncateMiddle } from '@naturalcycles/js-lib'
10
10
  import { ValidationError, ValidationOptions } from 'joi'
11
11
  import { AnySchemaTyped } from './joi.model'
12
12
  import { JoiValidationError } from './joi.validation.error'
@@ -146,11 +146,11 @@ function createError(value: any, err: ValidationError, objectName?: string): Joi
146
146
 
147
147
  const annotation = err.annotate(stripColors)
148
148
 
149
- if (annotation.length > 2000) {
149
+ if (annotation.length > 4000) {
150
150
  // Annotation message is too big and will be replaced by stringified `error.details` instead
151
+
151
152
  tokens.push(
152
- annotation.slice(0, 2000),
153
- `... ${Math.ceil(annotation.length / 1024)} KB message truncated`,
153
+ _truncateMiddle(annotation, 4000, `\n... ${_hb(annotation.length)} message truncated ...\n`),
154
154
  )
155
155
 
156
156
  // Up to 5 `details`
@@ -167,5 +167,6 @@ function createError(value: any, err: ValidationError, objectName?: string): Joi
167
167
  joiValidationErrorItems: err.details,
168
168
  ...(objectName && { joiValidationObjectName: objectName }),
169
169
  ...(objectId && { joiValidationObjectId: objectId }),
170
+ annotation,
170
171
  })
171
172
  }