@naturalcycles/nodejs-lib 15.90.0 → 15.90.2

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,4 +1,4 @@
1
- import { type StdioOptions } from 'node:child_process';
1
+ import type { StdioOptions } from 'node:child_process';
2
2
  import { AppError } from '@naturalcycles/js-lib/error/error.util.js';
3
3
  import type { AnyObject, NumberOfMilliseconds } from '@naturalcycles/js-lib/types';
4
4
  /**
@@ -1,4 +1,4 @@
1
- import { type Base64String, type StringMap } from '@naturalcycles/js-lib/types';
1
+ import type { Base64String, StringMap } from '@naturalcycles/js-lib/types';
2
2
  /**
3
3
  * Using aes-256-cbc.
4
4
  */
@@ -1,4 +1,4 @@
1
- import { type CommonLogger, type CommonLogLevel } from '@naturalcycles/js-lib/log';
1
+ import type { CommonLogger, CommonLogLevel } from '@naturalcycles/js-lib/log';
2
2
  import type { AnyObject } from '@naturalcycles/js-lib/types';
3
3
  import type { SlackAttachmentField, SlackMessage, SlackServiceCfg } from './slack.service.model.js';
4
4
  /**
@@ -1,6 +1,6 @@
1
1
  import { localTime } from '@naturalcycles/js-lib/datetime/localTime.js';
2
2
  import { getFetcher } from '@naturalcycles/js-lib/http';
3
- import { createCommonLoggerAtLevel, } from '@naturalcycles/js-lib/log';
3
+ import { createCommonLoggerAtLevel } from '@naturalcycles/js-lib/log';
4
4
  import { _omit } from '@naturalcycles/js-lib/object/object.util.js';
5
5
  import { PQueue } from '@naturalcycles/js-lib/promise/pQueue.js';
6
6
  import { _inspect } from '../index.js';
@@ -1,15 +1,15 @@
1
- import { type Transform } from 'node:stream';
1
+ import type { Transform } from 'node:stream';
2
2
  import type { ReadableStream as WebReadableStream } from 'node:stream/web';
3
- import { type ZlibOptions, type ZstdOptions } from 'node:zlib';
4
- import { type AbortableAsyncMapper, type AsyncIndexedMapper, type AsyncPredicate, type END, type IndexedMapper, type Integer, type NonNegativeInteger, type PositiveInteger, type Predicate, type SKIP } from '@naturalcycles/js-lib/types';
3
+ import type { ZlibOptions, ZstdOptions } from 'node:zlib';
4
+ import type { AbortableAsyncMapper, AsyncIndexedMapper, AsyncPredicate, END, IndexedMapper, Integer, NonNegativeInteger, PositiveInteger, Predicate, SKIP } from '@naturalcycles/js-lib/types';
5
5
  import type { ReadableTyped, TransformOptions, TransformTyped, WritableTyped } from './stream.model.js';
6
- import { type TransformLogProgressOptions } from './transform/transformLogProgress.js';
7
- import { type TransformMapOptions } from './transform/transformMap.js';
8
- import { type TransformMapSimpleOptions } from './transform/transformMapSimple.js';
9
- import { type TransformMapSyncOptions } from './transform/transformMapSync.js';
10
- import { type TransformOffsetOptions } from './transform/transformOffset.js';
11
- import { type TransformThrottleOptions } from './transform/transformThrottle.js';
12
- import { type TransformWarmupOptions } from './transform/transformWarmup.js';
6
+ import type { TransformLogProgressOptions } from './transform/transformLogProgress.js';
7
+ import type { TransformMapOptions } from './transform/transformMap.js';
8
+ import type { TransformMapSimpleOptions } from './transform/transformMapSimple.js';
9
+ import type { TransformMapSyncOptions } from './transform/transformMapSync.js';
10
+ import type { TransformOffsetOptions } from './transform/transformOffset.js';
11
+ import type { TransformThrottleOptions } from './transform/transformThrottle.js';
12
+ import type { TransformWarmupOptions } from './transform/transformWarmup.js';
13
13
  export declare class Pipeline<T = unknown> {
14
14
  private readonly source;
15
15
  private transforms;
@@ -1,8 +1,8 @@
1
1
  import { Readable } from 'node:stream';
2
2
  import { pipeline } from 'node:stream/promises';
3
- import { createGzip, createUnzip, createZstdCompress, createZstdDecompress, } from 'node:zlib';
3
+ import { createGzip, createUnzip, createZstdCompress, createZstdDecompress } from 'node:zlib';
4
4
  import { createAbortableSignal } from '@naturalcycles/js-lib';
5
- import { _passthroughPredicate, } from '@naturalcycles/js-lib/types';
5
+ import { _passthroughPredicate } from '@naturalcycles/js-lib/types';
6
6
  import { fs2 } from '../fs/fs2.js';
7
7
  import { zstdLevelToOptions } from '../zip/zip.util.js';
8
8
  import { createReadStreamAsNDJson } from './ndjson/createReadStreamAsNDJson.js';
@@ -16,9 +16,9 @@ import { transformFlatten, transformFlattenIfNeeded } from './transform/transfor
16
16
  // oxlint-disable-next-line import/no-cycle -- intentional cycle
17
17
  import { transformFork } from './transform/transformFork.js';
18
18
  import { transformLimit } from './transform/transformLimit.js';
19
- import { transformLogProgress, } from './transform/transformLogProgress.js';
19
+ import { transformLogProgress } from './transform/transformLogProgress.js';
20
20
  import { transformMap } from './transform/transformMap.js';
21
- import { transformMapSimple, } from './transform/transformMapSimple.js';
21
+ import { transformMapSimple } from './transform/transformMapSimple.js';
22
22
  import { transformMapSync } from './transform/transformMapSync.js';
23
23
  import { transformOffset } from './transform/transformOffset.js';
24
24
  import { transformSplitOnNewline } from './transform/transformSplit.js';
@@ -1,4 +1,4 @@
1
- import { type ReadableOptions } from 'node:stream';
1
+ import type { ReadableOptions } from 'node:stream';
2
2
  import type { ReadableTyped } from '../stream.model.js';
3
3
  /**
4
4
  * Convenience function to create a Readable that can be pushed into (similar to RxJS Subject).
@@ -1,6 +1,7 @@
1
- import { type AbortableSignal } from '@naturalcycles/js-lib';
1
+ import type { AbortableSignal } from '@naturalcycles/js-lib';
2
2
  import { ErrorMode } from '@naturalcycles/js-lib/error';
3
- import { type AbortableAsyncMapper, type AsyncPredicate, END, type NumberOfSeconds, type PositiveInteger, type Predicate, type Promisable, SKIP, type StringMap, type UnixTimestampMillis } from '@naturalcycles/js-lib/types';
3
+ import { END, SKIP } from '@naturalcycles/js-lib/types';
4
+ import type { AbortableAsyncMapper, AsyncPredicate, NumberOfSeconds, PositiveInteger, Predicate, Promisable, StringMap, UnixTimestampMillis } from '@naturalcycles/js-lib/types';
4
5
  import type { TransformOptions, TransformTyped } from '../stream.model.js';
5
6
  export interface TransformMapOptions<IN = any, OUT = IN> extends TransformOptions {
6
7
  /**
@@ -5,7 +5,7 @@ import { _anyToError, _assert, ErrorMode } from '@naturalcycles/js-lib/error';
5
5
  import { createCommonLoggerAtLevel } from '@naturalcycles/js-lib/log';
6
6
  import { pDefer } from '@naturalcycles/js-lib/promise/pDefer.js';
7
7
  import { _stringify } from '@naturalcycles/js-lib/string';
8
- import { END, SKIP, } from '@naturalcycles/js-lib/types';
8
+ import { END, SKIP } from '@naturalcycles/js-lib/types';
9
9
  import { yellow } from '../../colors/colors.js';
10
10
  import { PIPELINE_GRACEFUL_ABORT } from '../stream.util.js';
11
11
  const WARMUP_CHECK_INTERVAL_MS = 1000;
@@ -1,9 +1,9 @@
1
- import { type ValidationFunction, type ValidationFunctionResult } from '@naturalcycles/js-lib';
2
- import { type AnyObject } from '@naturalcycles/js-lib/types';
3
- import type { ZodType } from '@naturalcycles/js-lib/zod';
1
+ import type { ValidationFunction, ValidationFunctionResult } from '@naturalcycles/js-lib';
2
+ import type { AnyObject } from '@naturalcycles/js-lib/types';
4
3
  import type { Ajv } from 'ajv';
5
4
  import { AjvValidationError } from './ajvValidationError.js';
6
- import { type JsonSchema, JsonSchemaTerminal } from './jsonSchemaBuilder.js';
5
+ import { JsonSchemaTerminal } from './jsonSchemaBuilder.js';
6
+ import type { JsonSchema } from './jsonSchemaBuilder.js';
7
7
  /**
8
8
  * On creation - compiles ajv validation function.
9
9
  * Provides convenient methods, error reporting, etc.
@@ -25,10 +25,6 @@ export declare class AjvSchema<IN = unknown, OUT = IN> {
25
25
  * correctly for some reason.
26
26
  */
27
27
  static create<IN, OUT = IN>(schema: SchemaHandledByAjv<IN, OUT>, cfg?: Partial<AjvSchemaCfg>): AjvSchema<IN, OUT>;
28
- /**
29
- * @deprecated Use `j` to build schemas, not `z` or `zod`.
30
- */
31
- static createFromZod<T extends ZodType<any, any, any>>(schema: T): AjvSchema<T['_input'], T['_output']>;
32
28
  static isJsonSchemaBuilder<IN, OUT>(schema: unknown): schema is JsonSchemaTerminal<IN, OUT, any>;
33
29
  readonly cfg: AjvSchemaCfg;
34
30
  /**
@@ -1,9 +1,8 @@
1
- import { _isObject, _lazyValue, } from '@naturalcycles/js-lib';
1
+ import { _isObject, _lazyValue } from '@naturalcycles/js-lib';
2
2
  import { _assert } from '@naturalcycles/js-lib/error';
3
3
  import { _deepCopy, _filterNullishValues } from '@naturalcycles/js-lib/object';
4
4
  import { _substringBefore } from '@naturalcycles/js-lib/string';
5
5
  import { _typeCast } from '@naturalcycles/js-lib/types';
6
- import { z } from '@naturalcycles/js-lib/zod';
7
6
  import { _inspect } from '../../string/inspect.js';
8
7
  import { AjvValidationError } from './ajvValidationError.js';
9
8
  import { getAjv } from './getAjv.js';
@@ -70,15 +69,6 @@ export class AjvSchema {
70
69
  AjvSchema.cacheAjvSchema(schema, ajvSchema);
71
70
  return ajvSchema;
72
71
  }
73
- /**
74
- * @deprecated Use `j` to build schemas, not `z` or `zod`.
75
- */
76
- static createFromZod(schema) {
77
- const jsonSchema = z.toJSONSchema(schema, {
78
- target: 'draft-2020-12',
79
- });
80
- return AjvSchema.create(jsonSchema);
81
- }
82
72
  static isJsonSchemaBuilder(schema) {
83
73
  return schema instanceof JsonSchemaTerminal;
84
74
  }
@@ -1,4 +1,4 @@
1
- import { type AnyObject } from '@naturalcycles/js-lib/types';
1
+ import type { AnyObject } from '@naturalcycles/js-lib/types';
2
2
  import type { JsonSchema } from '../jsonSchemaBuilder.js';
3
3
  /**
4
4
  * Each row must be an object (current limitation).
@@ -1,4 +1,5 @@
1
- import { Ajv2020, type Options } from 'ajv/dist/2020.js';
1
+ import { Ajv2020 } from 'ajv/dist/2020.js';
2
+ import type { Options } from 'ajv/dist/2020.js';
2
3
  /**
3
4
  * Return cached instance of Ajv with default (recommended) options.
4
5
  *
@@ -1,5 +1,5 @@
1
1
  import type { Set2 } from '@naturalcycles/js-lib/object';
2
- import { type AnyObject, type BaseDBEntity, type IANATimezone, type Inclusiveness, type IsoDate, type IsoDateTime, type IsoMonth, type NumberEnum, type StringEnum, type StringMap, type UnixTimestamp, type UnixTimestampMillis } from '@naturalcycles/js-lib/types';
2
+ import type { AnyObject, BaseDBEntity, IANATimezone, Inclusiveness, IsoDate, IsoDateTime, IsoMonth, NumberEnum, StringEnum, StringMap, UnixTimestamp, UnixTimestampMillis } from '@naturalcycles/js-lib/types';
3
3
  export declare const j: {
4
4
  /**
5
5
  * Matches literally any value - equivalent to TypeScript's `any` type.
@@ -244,17 +244,15 @@ export interface JsonSchemaStringEmailOptions {
244
244
  export declare class JsonSchemaIsoDateBuilder<Opt extends boolean = false> extends JsonSchemaAnyBuilder<string | IsoDate, IsoDate, Opt> {
245
245
  constructor();
246
246
  /**
247
- * @param optionalValues List of values that should be considered/converted as `undefined`.
247
+ * @param nullValue Pass `null` to have `null` values be considered/converted as `undefined`.
248
248
  *
249
- * This `optionalValues` feature only works when the current schema is nested in an object or array schema,
249
+ * This `null` feature only works when the current schema is nested in an object or array schema,
250
250
  * due to how mutability works in Ajv.
251
251
  *
252
- * Make sure this `optional()` call is at the end of your call chain.
253
- *
254
- * When `null` is included in optionalValues, the return type becomes `JsonSchemaTerminal`
252
+ * When `null` is passed, the return type becomes `JsonSchemaTerminal`
255
253
  * (no further chaining allowed) because the schema is wrapped in an anyOf structure.
256
254
  */
257
- optional<T extends readonly null[] | undefined = undefined>(optionalValues?: T): T extends readonly null[] ? JsonSchemaTerminal<string | IsoDate | undefined, IsoDate | undefined, true> : JsonSchemaAnyBuilder<string | IsoDate | undefined, IsoDate | undefined, true>;
255
+ optional<N extends null | undefined = undefined>(nullValue?: N): N extends null ? JsonSchemaTerminal<string | IsoDate | null | undefined, IsoDate | undefined, true> : JsonSchemaAnyBuilder<string | IsoDate | undefined, IsoDate | undefined, true>;
258
256
  before(date: string): this;
259
257
  sameOrBefore(date: string): this;
260
258
  after(date: string): this;
@@ -338,7 +336,7 @@ export declare class JsonSchemaObjectBuilder<IN extends AnyObject, OUT extends A
338
336
  * When `null` is passed, the return type becomes `JsonSchemaTerminal`
339
337
  * (no further chaining allowed) because the schema is wrapped in an anyOf structure.
340
338
  */
341
- optional<N extends null | undefined = undefined>(nullValue?: N): N extends null ? JsonSchemaTerminal<IN | undefined, OUT | undefined, true> : JsonSchemaAnyBuilder<IN | undefined, OUT | undefined, true>;
339
+ optional<N extends null | undefined = undefined>(nullValue?: N): N extends null ? JsonSchemaTerminal<IN | null | undefined, OUT | undefined, true> : JsonSchemaAnyBuilder<IN | undefined, OUT | undefined, true>;
342
340
  /**
343
341
  * When set, the validation will not strip away properties that are not specified explicitly in the schema.
344
342
  */
@@ -4,7 +4,7 @@ import { _isUndefined, _numberEnumValues, _stringEnumValues, getEnumType, } from
4
4
  import { _uniq } from '@naturalcycles/js-lib/array';
5
5
  import { _assert } from '@naturalcycles/js-lib/error';
6
6
  import { _sortObject } from '@naturalcycles/js-lib/object';
7
- import { _objectAssign, _typeCast, JWT_REGEX, } from '@naturalcycles/js-lib/types';
7
+ import { _objectAssign, _typeCast, JWT_REGEX } from '@naturalcycles/js-lib/types';
8
8
  import { BASE64URL_REGEX, COUNTRY_CODE_REGEX, CURRENCY_REGEX, IPV4_REGEX, IPV6_REGEX, LANGUAGE_TAG_REGEX, SEMVER_REGEX, SLUG_REGEX, URL_REGEX, UUID_REGEX, } from '../regexes.js';
9
9
  import { TIMEZONES } from '../timezones.js';
10
10
  import { isEveryItemNumber, isEveryItemPrimitive, isEveryItemString, JSON_SCHEMA_ORDER, mergeJsonSchemaObjects, } from './jsonSchemaBuilder.util.js';
@@ -509,27 +509,26 @@ export class JsonSchemaIsoDateBuilder extends JsonSchemaAnyBuilder {
509
509
  });
510
510
  }
511
511
  /**
512
- * @param optionalValues List of values that should be considered/converted as `undefined`.
512
+ * @param nullValue Pass `null` to have `null` values be considered/converted as `undefined`.
513
513
  *
514
- * This `optionalValues` feature only works when the current schema is nested in an object or array schema,
514
+ * This `null` feature only works when the current schema is nested in an object or array schema,
515
515
  * due to how mutability works in Ajv.
516
516
  *
517
- * Make sure this `optional()` call is at the end of your call chain.
518
- *
519
- * When `null` is included in optionalValues, the return type becomes `JsonSchemaTerminal`
517
+ * When `null` is passed, the return type becomes `JsonSchemaTerminal`
520
518
  * (no further chaining allowed) because the schema is wrapped in an anyOf structure.
521
519
  */
522
- optional(optionalValues) {
523
- if (!optionalValues) {
520
+ optional(nullValue) {
521
+ if (nullValue === undefined) {
524
522
  return super.optional();
525
523
  }
526
- _typeCast(optionalValues);
527
- const optionalBuilder = this.cloneAndUpdateSchema({ optionalField: true });
528
- const newBuilder = new JsonSchemaTerminal({
529
- anyOf: [{ type: 'null', optionalValues }, optionalBuilder.build()],
524
+ // When `null` is specified, we want `null` to be stripped and the value to become `undefined`,
525
+ // so we must allow `null` values to be parsed by Ajv,
526
+ // but the typing should not reflect that.
527
+ // We also cannot accept more rules attached, since we're not building an ObjectSchema anymore.
528
+ return new JsonSchemaTerminal({
529
+ anyOf: [{ type: 'null', optionalValues: [null] }, this.build()],
530
530
  optionalField: true,
531
531
  });
532
- return newBuilder;
533
532
  }
534
533
  before(date) {
535
534
  return this.cloneAndUpdateSchema({ IsoDate: { before: date } });
@@ -760,7 +759,7 @@ export class JsonSchemaObjectBuilder extends JsonSchemaAnyBuilder {
760
759
  * (no further chaining allowed) because the schema is wrapped in an anyOf structure.
761
760
  */
762
761
  optional(nullValue) {
763
- if (typeof nullValue === 'undefined') {
762
+ if (nullValue === undefined) {
764
763
  return super.optional();
765
764
  }
766
765
  // When `null` is specified, we want `null` to be stripped and the value to become `undefined`,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@naturalcycles/nodejs-lib",
3
3
  "type": "module",
4
- "version": "15.90.0",
4
+ "version": "15.90.2",
5
5
  "dependencies": {
6
6
  "@naturalcycles/js-lib": "^15",
7
7
  "@types/js-yaml": "^4",
@@ -18,6 +18,7 @@
18
18
  "yargs": "^18"
19
19
  },
20
20
  "devDependencies": {
21
+ "@typescript/native-preview": "^7.0.0-0",
21
22
  "@naturalcycles/dev-lib": "18.4.2"
22
23
  },
23
24
  "exports": {
@@ -1,4 +1,5 @@
1
- import { execSync, spawn, spawnSync, type StdioOptions } from 'node:child_process'
1
+ import { execSync, spawn, spawnSync } from 'node:child_process'
2
+ import type { StdioOptions } from 'node:child_process'
2
3
  import { _since } from '@naturalcycles/js-lib/datetime/time.util.js'
3
4
  import { AppError } from '@naturalcycles/js-lib/error/error.util.js'
4
5
  import { _substringAfterLast } from '@naturalcycles/js-lib/string/string.util.js'
@@ -1,5 +1,6 @@
1
1
  import crypto from 'node:crypto'
2
- import { _stringMapEntries, type Base64String, type StringMap } from '@naturalcycles/js-lib/types'
2
+ import { _stringMapEntries } from '@naturalcycles/js-lib/types'
3
+ import type { Base64String, StringMap } from '@naturalcycles/js-lib/types'
3
4
  import { md5AsBuffer, sha256AsBuffer } from './hash.util.js'
4
5
 
5
6
  const algorithm = 'aes-256-cbc'
@@ -1,14 +1,13 @@
1
1
  import { localTime } from '@naturalcycles/js-lib/datetime/localTime.js'
2
- import { type Fetcher, getFetcher } from '@naturalcycles/js-lib/http'
3
- import {
4
- type CommonLogger,
5
- type CommonLogLevel,
6
- createCommonLoggerAtLevel,
7
- } from '@naturalcycles/js-lib/log'
2
+ import { getFetcher } from '@naturalcycles/js-lib/http'
3
+ import type { Fetcher } from '@naturalcycles/js-lib/http'
4
+ import { createCommonLoggerAtLevel } from '@naturalcycles/js-lib/log'
5
+ import type { CommonLogger, CommonLogLevel } from '@naturalcycles/js-lib/log'
8
6
  import { _omit } from '@naturalcycles/js-lib/object/object.util.js'
9
7
  import { PQueue } from '@naturalcycles/js-lib/promise/pQueue.js'
10
8
  import type { AnyObject } from '@naturalcycles/js-lib/types'
11
- import { _inspect, type InspectAnyOptions } from '../index.js'
9
+ import { _inspect } from '../index.js'
10
+ import type { InspectAnyOptions } from '../index.js'
12
11
  import type {
13
12
  SlackApiBody,
14
13
  SlackAttachmentField,
@@ -1,27 +1,22 @@
1
- import { Readable, type Transform } from 'node:stream'
1
+ import { Readable } from 'node:stream'
2
+ import type { Transform } from 'node:stream'
2
3
  import { pipeline } from 'node:stream/promises'
3
4
  import type { ReadableStream as WebReadableStream } from 'node:stream/web'
4
- import {
5
- createGzip,
6
- createUnzip,
7
- createZstdCompress,
8
- createZstdDecompress,
9
- type ZlibOptions,
10
- type ZstdOptions,
11
- } from 'node:zlib'
5
+ import { createGzip, createUnzip, createZstdCompress, createZstdDecompress } from 'node:zlib'
6
+ import type { ZlibOptions, ZstdOptions } from 'node:zlib'
12
7
  import { createAbortableSignal } from '@naturalcycles/js-lib'
13
- import {
14
- _passthroughPredicate,
15
- type AbortableAsyncMapper,
16
- type AsyncIndexedMapper,
17
- type AsyncPredicate,
18
- type END,
19
- type IndexedMapper,
20
- type Integer,
21
- type NonNegativeInteger,
22
- type PositiveInteger,
23
- type Predicate,
24
- type SKIP,
8
+ import { _passthroughPredicate } from '@naturalcycles/js-lib/types'
9
+ import type {
10
+ AbortableAsyncMapper,
11
+ AsyncIndexedMapper,
12
+ AsyncPredicate,
13
+ END,
14
+ IndexedMapper,
15
+ Integer,
16
+ NonNegativeInteger,
17
+ PositiveInteger,
18
+ Predicate,
19
+ SKIP,
25
20
  } from '@naturalcycles/js-lib/types'
26
21
  import { fs2 } from '../fs/fs2.js'
27
22
  import { zstdLevelToOptions } from '../zip/zip.util.js'
@@ -42,21 +37,22 @@ import { transformFlatten, transformFlattenIfNeeded } from './transform/transfor
42
37
  // oxlint-disable-next-line import/no-cycle -- intentional cycle
43
38
  import { transformFork } from './transform/transformFork.js'
44
39
  import { transformLimit } from './transform/transformLimit.js'
45
- import {
46
- transformLogProgress,
47
- type TransformLogProgressOptions,
48
- } from './transform/transformLogProgress.js'
49
- import { transformMap, type TransformMapOptions } from './transform/transformMap.js'
50
- import {
51
- transformMapSimple,
52
- type TransformMapSimpleOptions,
53
- } from './transform/transformMapSimple.js'
54
- import { transformMapSync, type TransformMapSyncOptions } from './transform/transformMapSync.js'
55
- import { transformOffset, type TransformOffsetOptions } from './transform/transformOffset.js'
40
+ import { transformLogProgress } from './transform/transformLogProgress.js'
41
+ import type { TransformLogProgressOptions } from './transform/transformLogProgress.js'
42
+ import { transformMap } from './transform/transformMap.js'
43
+ import type { TransformMapOptions } from './transform/transformMap.js'
44
+ import { transformMapSimple } from './transform/transformMapSimple.js'
45
+ import type { TransformMapSimpleOptions } from './transform/transformMapSimple.js'
46
+ import { transformMapSync } from './transform/transformMapSync.js'
47
+ import type { TransformMapSyncOptions } from './transform/transformMapSync.js'
48
+ import { transformOffset } from './transform/transformOffset.js'
49
+ import type { TransformOffsetOptions } from './transform/transformOffset.js'
56
50
  import { transformSplitOnNewline } from './transform/transformSplit.js'
57
51
  import { transformTap, transformTapSync } from './transform/transformTap.js'
58
- import { transformThrottle, type TransformThrottleOptions } from './transform/transformThrottle.js'
59
- import { transformWarmup, type TransformWarmupOptions } from './transform/transformWarmup.js'
52
+ import { transformThrottle } from './transform/transformThrottle.js'
53
+ import type { TransformThrottleOptions } from './transform/transformThrottle.js'
54
+ import { transformWarmup } from './transform/transformWarmup.js'
55
+ import type { TransformWarmupOptions } from './transform/transformWarmup.js'
60
56
  import { writablePushToArray } from './writable/writablePushToArray.js'
61
57
  import { writableVoid } from './writable/writableVoid.js'
62
58
 
@@ -1,4 +1,5 @@
1
- import { Readable, type ReadableOptions, Transform } from 'node:stream'
1
+ import { Readable, Transform } from 'node:stream'
2
+ import type { ReadableOptions } from 'node:stream'
2
3
  import type { ReadableTyped } from '../stream.model.js'
3
4
 
4
5
  /**
@@ -1,6 +1,8 @@
1
1
  import { Readable } from 'node:stream'
2
- import { type CommonLogger, createCommonLoggerAtLevel } from '@naturalcycles/js-lib/log'
3
- import { type DeferredPromise, pDefer } from '@naturalcycles/js-lib/promise/pDefer.js'
2
+ import { createCommonLoggerAtLevel } from '@naturalcycles/js-lib/log'
3
+ import type { CommonLogger } from '@naturalcycles/js-lib/log'
4
+ import { pDefer } from '@naturalcycles/js-lib/promise/pDefer.js'
5
+ import type { DeferredPromise } from '@naturalcycles/js-lib/promise/pDefer.js'
4
6
  import { pMap } from '@naturalcycles/js-lib/promise/pMap.js'
5
7
  import type { ReadableTyped } from '@naturalcycles/nodejs-lib/stream'
6
8
  import type { TransformOptions } from '../stream.model.js'
@@ -1,6 +1,7 @@
1
1
  import { Transform } from 'node:stream'
2
2
  import { createCommonLoggerAtLevel } from '@naturalcycles/js-lib/log'
3
- import { type DeferredPromise, pDefer } from '@naturalcycles/js-lib/promise/pDefer.js'
3
+ import { pDefer } from '@naturalcycles/js-lib/promise/pDefer.js'
4
+ import type { DeferredPromise } from '@naturalcycles/js-lib/promise/pDefer.js'
4
5
  // oxlint-disable-next-line import/no-cycle -- intentional cycle
5
6
  import { Pipeline } from '../pipeline.js'
6
7
  import { createReadable } from '../readable/createReadable.js'
@@ -1,22 +1,22 @@
1
1
  import { Transform } from 'node:stream'
2
- import { _hc, type AbortableSignal } from '@naturalcycles/js-lib'
2
+ import { _hc } from '@naturalcycles/js-lib'
3
+ import type { AbortableSignal } from '@naturalcycles/js-lib'
3
4
  import { _since } from '@naturalcycles/js-lib/datetime'
4
5
  import { _anyToError, _assert, ErrorMode } from '@naturalcycles/js-lib/error'
5
6
  import { createCommonLoggerAtLevel } from '@naturalcycles/js-lib/log'
6
7
  import type { DeferredPromise } from '@naturalcycles/js-lib/promise'
7
8
  import { pDefer } from '@naturalcycles/js-lib/promise/pDefer.js'
8
9
  import { _stringify } from '@naturalcycles/js-lib/string'
9
- import {
10
- type AbortableAsyncMapper,
11
- type AsyncPredicate,
12
- END,
13
- type NumberOfSeconds,
14
- type PositiveInteger,
15
- type Predicate,
16
- type Promisable,
17
- SKIP,
18
- type StringMap,
19
- type UnixTimestampMillis,
10
+ import { END, SKIP } from '@naturalcycles/js-lib/types'
11
+ import type {
12
+ AbortableAsyncMapper,
13
+ AsyncPredicate,
14
+ NumberOfSeconds,
15
+ PositiveInteger,
16
+ Predicate,
17
+ Promisable,
18
+ StringMap,
19
+ UnixTimestampMillis,
20
20
  } from '@naturalcycles/js-lib/types'
21
21
  import { yellow } from '../../colors/colors.js'
22
22
  import type { TransformOptions, TransformTyped } from '../stream.model.js'
@@ -1,6 +1,6 @@
1
1
  const started = Date.now()
2
- import { workerData, parentPort } from 'node:worker_threads'
3
2
  import { inspect } from 'node:util'
3
+ import { workerData, parentPort } from 'node:worker_threads'
4
4
  const { workerFile, workerIndex, logEvery = 1000, metric = 'worker', silent } = workerData || {}
5
5
 
6
6
  if (!workerFile) {
@@ -1,6 +1,7 @@
1
1
  import { Writable } from 'node:stream'
2
2
  import { createCommonLoggerAtLevel } from '@naturalcycles/js-lib/log'
3
- import { type DeferredPromise, pDefer } from '@naturalcycles/js-lib/promise/pDefer.js'
3
+ import { pDefer } from '@naturalcycles/js-lib/promise/pDefer.js'
4
+ import type { DeferredPromise } from '@naturalcycles/js-lib/promise/pDefer.js'
4
5
  import type { NonNegativeInteger, Predicate } from '@naturalcycles/js-lib/types'
5
6
  import { Pipeline } from '../pipeline.js'
6
7
  import { createReadable } from '../readable/createReadable.js'
@@ -1,20 +1,16 @@
1
- import {
2
- _isObject,
3
- _lazyValue,
4
- type ValidationFunction,
5
- type ValidationFunctionResult,
6
- } from '@naturalcycles/js-lib'
1
+ import { _isObject, _lazyValue } from '@naturalcycles/js-lib'
2
+ import type { ValidationFunction, ValidationFunctionResult } from '@naturalcycles/js-lib'
7
3
  import { _assert } from '@naturalcycles/js-lib/error'
8
4
  import { _deepCopy, _filterNullishValues } from '@naturalcycles/js-lib/object'
9
5
  import { _substringBefore } from '@naturalcycles/js-lib/string'
10
- import { _typeCast, type AnyObject } from '@naturalcycles/js-lib/types'
11
- import type { ZodType } from '@naturalcycles/js-lib/zod'
12
- import { z } from '@naturalcycles/js-lib/zod'
6
+ import { _typeCast } from '@naturalcycles/js-lib/types'
7
+ import type { AnyObject } from '@naturalcycles/js-lib/types'
13
8
  import type { Ajv, ErrorObject } from 'ajv'
14
9
  import { _inspect } from '../../string/inspect.js'
15
10
  import { AjvValidationError } from './ajvValidationError.js'
16
11
  import { getAjv } from './getAjv.js'
17
- import { type JsonSchema, JsonSchemaTerminal } from './jsonSchemaBuilder.js'
12
+ import { JsonSchemaTerminal } from './jsonSchemaBuilder.js'
13
+ import type { JsonSchema } from './jsonSchemaBuilder.js'
18
14
 
19
15
  /**
20
16
  * On creation - compiles ajv validation function.
@@ -93,19 +89,6 @@ export class AjvSchema<IN = unknown, OUT = IN> {
93
89
  return ajvSchema
94
90
  }
95
91
 
96
- /**
97
- * @deprecated Use `j` to build schemas, not `z` or `zod`.
98
- */
99
- static createFromZod<T extends ZodType<any, any, any>>(
100
- schema: T,
101
- ): AjvSchema<T['_input'], T['_output']> {
102
- const jsonSchema = z.toJSONSchema(schema, {
103
- target: 'draft-2020-12',
104
- }) as unknown as JsonSchema<T['_input'], T['_output']>
105
-
106
- return AjvSchema.create(jsonSchema)
107
- }
108
-
109
92
  static isJsonSchemaBuilder<IN, OUT>(schema: unknown): schema is JsonSchemaTerminal<IN, OUT, any> {
110
93
  return schema instanceof JsonSchemaTerminal
111
94
  }
@@ -1,5 +1,6 @@
1
1
  import { _uniq } from '@naturalcycles/js-lib/array'
2
- import { _stringMapEntries, type AnyObject, type StringMap } from '@naturalcycles/js-lib/types'
2
+ import { _stringMapEntries } from '@naturalcycles/js-lib/types'
3
+ import type { AnyObject, StringMap } from '@naturalcycles/js-lib/types'
3
4
  import type { JsonSchema } from '../jsonSchemaBuilder.js'
4
5
 
5
6
  type PrimitiveType = 'undefined' | 'null' | 'boolean' | 'string' | 'number'
@@ -3,7 +3,8 @@ import { _assert } from '@naturalcycles/js-lib/error'
3
3
  import { _deepCopy, _mapObject, Set2 } from '@naturalcycles/js-lib/object'
4
4
  import { _substringAfterLast } from '@naturalcycles/js-lib/string'
5
5
  import type { AnyObject } from '@naturalcycles/js-lib/types'
6
- import { Ajv2020, type Options, type ValidateFunction } from 'ajv/dist/2020.js'
6
+ import { Ajv2020 } from 'ajv/dist/2020.js'
7
+ import type { Options, ValidateFunction } from 'ajv/dist/2020.js'
7
8
  import { validTLDs } from '../tlds.js'
8
9
  import type {
9
10
  CustomConverterFn,
@@ -11,22 +11,20 @@ import { _uniq } from '@naturalcycles/js-lib/array'
11
11
  import { _assert } from '@naturalcycles/js-lib/error'
12
12
  import type { Set2 } from '@naturalcycles/js-lib/object'
13
13
  import { _sortObject } from '@naturalcycles/js-lib/object'
14
- import {
15
- _objectAssign,
16
- _typeCast,
17
- type AnyObject,
18
- type BaseDBEntity,
19
- type IANATimezone,
20
- type Inclusiveness,
21
- type IsoDate,
22
- type IsoDateTime,
23
- type IsoMonth,
24
- JWT_REGEX,
25
- type NumberEnum,
26
- type StringEnum,
27
- type StringMap,
28
- type UnixTimestamp,
29
- type UnixTimestampMillis,
14
+ import { _objectAssign, _typeCast, JWT_REGEX } from '@naturalcycles/js-lib/types'
15
+ import type {
16
+ AnyObject,
17
+ BaseDBEntity,
18
+ IANATimezone,
19
+ Inclusiveness,
20
+ IsoDate,
21
+ IsoDateTime,
22
+ IsoMonth,
23
+ NumberEnum,
24
+ StringEnum,
25
+ StringMap,
26
+ UnixTimestamp,
27
+ UnixTimestampMillis,
30
28
  } from '@naturalcycles/js-lib/types'
31
29
  import {
32
30
  BASE64URL_REGEX,
@@ -704,39 +702,31 @@ export class JsonSchemaIsoDateBuilder<Opt extends boolean = false> extends JsonS
704
702
  }
705
703
 
706
704
  /**
707
- * @param optionalValues List of values that should be considered/converted as `undefined`.
705
+ * @param nullValue Pass `null` to have `null` values be considered/converted as `undefined`.
708
706
  *
709
- * This `optionalValues` feature only works when the current schema is nested in an object or array schema,
707
+ * This `null` feature only works when the current schema is nested in an object or array schema,
710
708
  * due to how mutability works in Ajv.
711
709
  *
712
- * Make sure this `optional()` call is at the end of your call chain.
713
- *
714
- * When `null` is included in optionalValues, the return type becomes `JsonSchemaTerminal`
710
+ * When `null` is passed, the return type becomes `JsonSchemaTerminal`
715
711
  * (no further chaining allowed) because the schema is wrapped in an anyOf structure.
716
712
  */
717
- override optional<T extends readonly null[] | undefined = undefined>(
718
- optionalValues?: T,
719
- ): T extends readonly null[]
720
- ? JsonSchemaTerminal<string | IsoDate | undefined, IsoDate | undefined, true>
713
+ override optional<N extends null | undefined = undefined>(
714
+ nullValue?: N,
715
+ ): N extends null
716
+ ? JsonSchemaTerminal<string | IsoDate | null | undefined, IsoDate | undefined, true>
721
717
  : JsonSchemaAnyBuilder<string | IsoDate | undefined, IsoDate | undefined, true> {
722
- if (!optionalValues) {
723
- return super.optional() as any
718
+ if (nullValue === undefined) {
719
+ return super.optional()
724
720
  }
725
721
 
726
- _typeCast<null[]>(optionalValues)
727
-
728
- const optionalBuilder = this.cloneAndUpdateSchema({ optionalField: true })
729
-
730
- const newBuilder = new JsonSchemaTerminal<
731
- string | IsoDate | undefined,
732
- IsoDate | undefined,
733
- true
734
- >({
735
- anyOf: [{ type: 'null', optionalValues }, optionalBuilder.build()],
722
+ // When `null` is specified, we want `null` to be stripped and the value to become `undefined`,
723
+ // so we must allow `null` values to be parsed by Ajv,
724
+ // but the typing should not reflect that.
725
+ // We also cannot accept more rules attached, since we're not building an ObjectSchema anymore.
726
+ return new JsonSchemaTerminal({
727
+ anyOf: [{ type: 'null', optionalValues: [null] }, this.build()],
736
728
  optionalField: true,
737
- })
738
-
739
- return newBuilder as any
729
+ }) as any
740
730
  }
741
731
 
742
732
  before(date: string): this {
@@ -1059,9 +1049,9 @@ export class JsonSchemaObjectBuilder<
1059
1049
  override optional<N extends null | undefined = undefined>(
1060
1050
  nullValue?: N,
1061
1051
  ): N extends null
1062
- ? JsonSchemaTerminal<IN | undefined, OUT | undefined, true>
1052
+ ? JsonSchemaTerminal<IN | null | undefined, OUT | undefined, true>
1063
1053
  : JsonSchemaAnyBuilder<IN | undefined, OUT | undefined, true> {
1064
- if (typeof nullValue === 'undefined') {
1054
+ if (nullValue === undefined) {
1065
1055
  return super.optional()
1066
1056
  }
1067
1057