@naturalcycles/nodejs-lib 15.5.0 → 15.7.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.
@@ -1,3 +1,5 @@
1
+ export declare function mockStringId(id: string): void;
2
+ export declare function unmockStringId(): void;
1
3
  /**
2
4
  * Generate cryptographically-secure string id.
3
5
  * Powered by `nanoid`.
@@ -1,11 +1,18 @@
1
1
  import { randomBytes } from 'node:crypto';
2
2
  import { ALPHABET_ALPHANUMERIC, ALPHABET_ALPHANUMERIC_LOWERCASE, ALPHABET_NONAMBIGUOUS, nanoIdCustomAlphabet, } from './nanoid.js';
3
+ let mockedStringId;
4
+ export function mockStringId(id) {
5
+ mockedStringId = id;
6
+ }
7
+ export function unmockStringId() {
8
+ mockedStringId = undefined;
9
+ }
3
10
  /**
4
11
  * Generate cryptographically-secure string id.
5
12
  * Powered by `nanoid`.
6
13
  */
7
14
  export function stringId(length = 16, alphabet = ALPHABET_ALPHANUMERIC_LOWERCASE) {
8
- return nanoIdCustomAlphabet(alphabet, length)();
15
+ return mockedStringId ?? nanoIdCustomAlphabet(alphabet, length)();
9
16
  }
10
17
  /**
11
18
  * Generate a string id of Base62 alphabet (same as "alphanumeric": A-Za-z0-9)
@@ -92,8 +92,8 @@ export class AjvSchema {
92
92
  dataVar: name,
93
93
  separator,
94
94
  });
95
- const strValue = _inspect(obj, { maxLen: 1000 });
96
- message = [message, 'Input: ' + strValue].join(separator);
95
+ const inputStringified = _inspect(obj, { maxLen: 4000 });
96
+ message = [message, 'Input: ' + inputStringified].join(separator);
97
97
  return new AjvValidationError(message, _filterNullishValues({
98
98
  errors,
99
99
  objectName,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@naturalcycles/nodejs-lib",
3
3
  "type": "module",
4
- "version": "15.5.0",
4
+ "version": "15.7.0",
5
5
  "dependencies": {
6
6
  "@naturalcycles/js-lib": "^15",
7
7
  "@types/js-yaml": "^4",
@@ -23,7 +23,7 @@
23
23
  },
24
24
  "devDependencies": {
25
25
  "@types/through2-concurrent": "^2",
26
- "@naturalcycles/dev-lib": "19.11.0"
26
+ "@naturalcycles/dev-lib": "18.4.2"
27
27
  },
28
28
  "exports": {
29
29
  ".": "./dist/index.js",
@@ -6,12 +6,21 @@ import {
6
6
  nanoIdCustomAlphabet,
7
7
  } from './nanoid.js'
8
8
 
9
+ let mockedStringId: string | undefined
10
+
11
+ export function mockStringId(id: string): void {
12
+ mockedStringId = id
13
+ }
14
+ export function unmockStringId(): void {
15
+ mockedStringId = undefined
16
+ }
17
+
9
18
  /**
10
19
  * Generate cryptographically-secure string id.
11
20
  * Powered by `nanoid`.
12
21
  */
13
22
  export function stringId(length = 16, alphabet = ALPHABET_ALPHANUMERIC_LOWERCASE): string {
14
- return nanoIdCustomAlphabet(alphabet, length)()
23
+ return mockedStringId ?? nanoIdCustomAlphabet(alphabet, length)()
15
24
  }
16
25
 
17
26
  /**
@@ -150,8 +150,8 @@ export class AjvSchema<T = unknown> {
150
150
  separator,
151
151
  })
152
152
 
153
- const strValue = _inspect(obj, { maxLen: 1000 })
154
- message = [message, 'Input: ' + strValue].join(separator)
153
+ const inputStringified = _inspect(obj, { maxLen: 4000 })
154
+ message = [message, 'Input: ' + inputStringified].join(separator)
155
155
 
156
156
  return new AjvValidationError(
157
157
  message,