@naturalcycles/nodejs-lib 15.74.0 → 15.75.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.
@@ -13,6 +13,7 @@ import { PIPELINE_GRACEFUL_ABORT } from './stream.util.js';
13
13
  import { transformChunk } from './transform/transformChunk.js';
14
14
  import { transformFilterSync } from './transform/transformFilter.js';
15
15
  import { transformFlatten, transformFlattenIfNeeded } from './transform/transformFlatten.js';
16
+ // oxlint-disable-next-line import/no-cycle -- intentional cycle
16
17
  import { transformFork } from './transform/transformFork.js';
17
18
  import { transformLimit } from './transform/transformLimit.js';
18
19
  import { transformLogProgress, } from './transform/transformLogProgress.js';
@@ -1,6 +1,7 @@
1
1
  import { Transform } from 'node:stream';
2
2
  import { createCommonLoggerAtLevel } from '@naturalcycles/js-lib/log';
3
3
  import { pDefer } from '@naturalcycles/js-lib/promise/pDefer.js';
4
+ // oxlint-disable-next-line import/no-cycle -- intentional cycle
4
5
  import { Pipeline } from '../pipeline.js';
5
6
  import { createReadable } from '../readable/createReadable.js';
6
7
  /**
@@ -13,6 +13,9 @@ const AJV_OPTIONS = {
13
13
  // these are important and kept same as default:
14
14
  // https://ajv.js.org/options.html#coercetypes
15
15
  coerceTypes: false, // while `false` - it won't mutate your input
16
+ strictTypes: true,
17
+ strictTuples: true,
18
+ allowUnionTypes: true, // supports oneOf/anyOf schemas
16
19
  };
17
20
  const AJV_NON_MUTATING_OPTIONS = {
18
21
  ...AJV_OPTIONS,
@@ -157,6 +157,7 @@ export class JsonSchemaTerminal {
157
157
  * Same as if it would be JSON.stringified.
158
158
  */
159
159
  build() {
160
+ _assert(!(this.schema.optionalField && this.schema.default !== undefined), '.optional() and .default() should not be used together - the default value makes .optional() redundant and causes incorrect type inference');
160
161
  const jsonSchema = _sortObject(JSON.parse(JSON.stringify(this.schema)), JSON_SCHEMA_ORDER);
161
162
  delete jsonSchema.optionalField;
162
163
  return jsonSchema;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@naturalcycles/nodejs-lib",
3
3
  "type": "module",
4
- "version": "15.74.0",
4
+ "version": "15.75.0",
5
5
  "dependencies": {
6
6
  "@naturalcycles/js-lib": "^15",
7
7
  "@types/js-yaml": "^4",
@@ -39,6 +39,7 @@ import { PIPELINE_GRACEFUL_ABORT } from './stream.util.js'
39
39
  import { transformChunk } from './transform/transformChunk.js'
40
40
  import { transformFilterSync } from './transform/transformFilter.js'
41
41
  import { transformFlatten, transformFlattenIfNeeded } from './transform/transformFlatten.js'
42
+ // oxlint-disable-next-line import/no-cycle -- intentional cycle
42
43
  import { transformFork } from './transform/transformFork.js'
43
44
  import { transformLimit } from './transform/transformLimit.js'
44
45
  import {
@@ -1,6 +1,7 @@
1
1
  import { Transform } from 'node:stream'
2
2
  import { createCommonLoggerAtLevel } from '@naturalcycles/js-lib/log'
3
3
  import { type DeferredPromise, pDefer } from '@naturalcycles/js-lib/promise/pDefer.js'
4
+ // oxlint-disable-next-line import/no-cycle -- intentional cycle
4
5
  import { Pipeline } from '../pipeline.js'
5
6
  import { createReadable } from '../readable/createReadable.js'
6
7
  import type { TransformOptions, TransformTyped } from '../stream.model.js'
@@ -21,6 +21,9 @@ const AJV_OPTIONS: Options = {
21
21
  // these are important and kept same as default:
22
22
  // https://ajv.js.org/options.html#coercetypes
23
23
  coerceTypes: false, // while `false` - it won't mutate your input
24
+ strictTypes: true,
25
+ strictTuples: true,
26
+ allowUnionTypes: true, // supports oneOf/anyOf schemas
24
27
  }
25
28
 
26
29
  const AJV_NON_MUTATING_OPTIONS: Options = {
@@ -247,6 +247,11 @@ export class JsonSchemaTerminal<IN, OUT, Opt> {
247
247
  * Same as if it would be JSON.stringified.
248
248
  */
249
249
  build(): JsonSchema<IN, OUT> {
250
+ _assert(
251
+ !(this.schema.optionalField && this.schema.default !== undefined),
252
+ '.optional() and .default() should not be used together - the default value makes .optional() redundant and causes incorrect type inference',
253
+ )
254
+
250
255
  const jsonSchema = _sortObject(
251
256
  JSON.parse(JSON.stringify(this.schema)),
252
257
  JSON_SCHEMA_ORDER,