@naturalcycles/nodejs-lib 12.86.1 → 12.88.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.
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.AbortableTransform = exports._pipelineToArray = exports._pipeline = void 0;
4
4
  const node_stream_1 = require("node:stream");
5
+ const promises_1 = require("node:stream/promises");
5
6
  const js_lib_1 = require("@naturalcycles/js-lib");
6
7
  const index_1 = require("../../index");
7
8
  /**
@@ -52,19 +53,17 @@ async function _pipeline(streams, opt = {}) {
52
53
  }
53
54
  });
54
55
  }
55
- return new Promise((resolve, reject) => {
56
- (0, node_stream_1.pipeline)(first, ...rest, (err) => {
57
- if (err) {
58
- if (opt.allowClose && err?.code === 'ERR_STREAM_PREMATURE_CLOSE') {
59
- console.log('_pipeline closed (as expected)');
60
- return resolve();
61
- }
62
- // console.log(`_pipeline error`, err)
63
- return reject(err);
64
- }
65
- resolve();
66
- });
67
- });
56
+ try {
57
+ return await (0, promises_1.pipeline)(first, ...rest);
58
+ }
59
+ catch (err) {
60
+ if (opt.allowClose && err?.code === 'ERR_STREAM_PREMATURE_CLOSE') {
61
+ console.log('_pipeline closed (as expected)');
62
+ return;
63
+ }
64
+ // console.log(`_pipeline error`, err)
65
+ throw err;
66
+ }
68
67
  }
69
68
  exports._pipeline = _pipeline;
70
69
  /**
@@ -25,3 +25,10 @@ export interface ObjectSchemaTyped<IN, OUT = IN> extends ObjectSchema<IN>, AnySc
25
25
  }
26
26
  export interface StringSchemaTyped extends StringSchema, AnySchemaTyped<string> {
27
27
  }
28
+ /**
29
+ * This type is useful to allow "joi schema merging".
30
+ * Because by default Joi doesn't allow normal merging.
31
+ * E.g `joiSchema.concat` doesn't play well when some property exists
32
+ * in both left and right side.
33
+ */
34
+ export type JoiSchemaObject<T> = Partial<Record<keyof T, any>>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@naturalcycles/nodejs-lib",
3
- "version": "12.86.1",
3
+ "version": "12.88.0",
4
4
  "scripts": {
5
5
  "prepare": "husky install",
6
6
  "docs-serve": "vuepress dev docs",
@@ -78,7 +78,7 @@
78
78
  "url": "https://github.com/NaturalCycles/nodejs-lib"
79
79
  },
80
80
  "engines": {
81
- "node": ">=16.10.0"
81
+ "node": ">=18.12.0"
82
82
  },
83
83
  "description": "Standard library for Node.js",
84
84
  "author": "Natural Cycles Team",
@@ -1,4 +1,5 @@
1
- import { pipeline, Readable, Transform, Writable } from 'node:stream'
1
+ import { Readable, Transform, Writable } from 'node:stream'
2
+ import { pipeline } from 'node:stream/promises'
2
3
  import { _last, AnyFunction, DeferredPromise, pDefer } from '@naturalcycles/js-lib'
3
4
  import { writablePushToArray } from '../../index'
4
5
 
@@ -74,20 +75,16 @@ export async function _pipeline(streams: AnyStream[], opt: PipelineOptions = {})
74
75
  })
75
76
  }
76
77
 
77
- return new Promise<void>((resolve, reject) => {
78
- pipeline(first, ...(rest as any[]), (err: Error) => {
79
- if (err) {
80
- if (opt.allowClose && (err as any)?.code === 'ERR_STREAM_PREMATURE_CLOSE') {
81
- console.log('_pipeline closed (as expected)')
82
- return resolve()
83
- }
84
- // console.log(`_pipeline error`, err)
85
- return reject(err)
86
- }
87
-
88
- resolve()
89
- })
90
- })
78
+ try {
79
+ return await pipeline(first, ...(rest as any[]))
80
+ } catch (err) {
81
+ if (opt.allowClose && (err as any)?.code === 'ERR_STREAM_PREMATURE_CLOSE') {
82
+ console.log('_pipeline closed (as expected)')
83
+ return
84
+ }
85
+ // console.log(`_pipeline error`, err)
86
+ throw err
87
+ }
91
88
  }
92
89
 
93
90
  /**
@@ -42,3 +42,11 @@ export interface ObjectSchemaTyped<IN, OUT = IN>
42
42
  extends ObjectSchema<IN>,
43
43
  AnySchemaTyped<IN, OUT> {}
44
44
  export interface StringSchemaTyped extends StringSchema, AnySchemaTyped<string> {}
45
+
46
+ /**
47
+ * This type is useful to allow "joi schema merging".
48
+ * Because by default Joi doesn't allow normal merging.
49
+ * E.g `joiSchema.concat` doesn't play well when some property exists
50
+ * in both left and right side.
51
+ */
52
+ export type JoiSchemaObject<T> = Partial<Record<keyof T, any>>