@naturalcycles/nodejs-lib 12.79.0 → 12.80.1

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/dist/fs/del.d.ts CHANGED
@@ -12,7 +12,7 @@ export interface DelOptions {
12
12
  debug?: boolean;
13
13
  dry?: boolean;
14
14
  }
15
- export declare type DelSingleOption = string;
15
+ export type DelSingleOption = string;
16
16
  /**
17
17
  * Delete files that match input patterns.
18
18
  *
@@ -78,7 +78,7 @@ export interface SlackMessageAttachment {
78
78
  /**
79
79
  * Return `null` to skip (filter out) the message completely.
80
80
  */
81
- export declare type SlackMessagePrefixHook<CTX = any> = (msg: SlackMessage<CTX>) => string[] | null | Promise<string[] | null>;
81
+ export type SlackMessagePrefixHook<CTX = any> = (msg: SlackMessage<CTX>) => string[] | null | Promise<string[] | null>;
82
82
  export interface SlackServiceCfg<CTX = any> {
83
83
  /**
84
84
  * Undefined means slack is disabled.
@@ -2,7 +2,7 @@
2
2
  /// <reference types="node" />
3
3
  import { Readable, Transform } from 'node:stream';
4
4
  import { DeferredPromise } from '@naturalcycles/js-lib';
5
- declare type AnyStream = NodeJS.ReadableStream | NodeJS.WritableStream | NodeJS.ReadWriteStream;
5
+ type AnyStream = NodeJS.ReadableStream | NodeJS.WritableStream | NodeJS.ReadWriteStream;
6
6
  export interface PipelineOptions {
7
7
  /**
8
8
  * Set to true to allow ERR_STREAM_PREMATURE_CLOSE.
@@ -5,8 +5,9 @@ const node_stream_1 = require("node:stream");
5
5
  const js_lib_1 = require("@naturalcycles/js-lib");
6
6
  function readableMap(readable, mapper) {
7
7
  let i = -1;
8
- // todo: check if we need to handle errors somehow specifically
9
- return readable.pipe(new node_stream_1.Transform({
8
+ const stream = readable
9
+ .on('error', err => stream.emit('error', err))
10
+ .pipe(new node_stream_1.Transform({
10
11
  objectMode: true,
11
12
  async transform(chunk, _enc, cb) {
12
13
  try {
@@ -25,5 +26,6 @@ function readableMap(readable, mapper) {
25
26
  }
26
27
  },
27
28
  }));
29
+ return stream;
28
30
  }
29
31
  exports.readableMap = readableMap;
@@ -1,6 +1,6 @@
1
1
  import { MemoCache } from '@naturalcycles/js-lib';
2
2
  import * as LRUCache from 'lru-cache';
3
- export declare type LRUMemoCacheOptions<KEY, VALUE> = Partial<LRUCache.Options<KEY, VALUE>>;
3
+ export type LRUMemoCacheOptions<KEY, VALUE> = Partial<LRUCache.Options<KEY, VALUE>>;
4
4
  /**
5
5
  * @example
6
6
  * Use it like this:
@@ -1,6 +1,6 @@
1
1
  /// <reference types="node" />
2
2
  import { AlternativesSchema, AnySchema, ArraySchema, BinarySchema, BooleanSchema, DateSchema, FunctionSchema, NumberSchema, ObjectSchema, StringSchema } from 'joi';
3
- export declare type SchemaTyped<IN, OUT = IN> = AnySchemaTyped<IN, OUT> | ArraySchemaTyped<IN> | AlternativesSchemaTyped<IN> | BinarySchemaTyped | BooleanSchemaTyped | DateSchemaTyped<IN> | FunctionSchemaTyped<IN> | NumberSchemaTyped | ObjectSchemaTyped<IN, OUT> | StringSchemaTyped;
3
+ export type SchemaTyped<IN, OUT = IN> = AnySchemaTyped<IN, OUT> | ArraySchemaTyped<IN> | AlternativesSchemaTyped<IN> | BinarySchemaTyped | BooleanSchemaTyped | DateSchemaTyped<IN> | FunctionSchemaTyped<IN> | NumberSchemaTyped | ObjectSchemaTyped<IN, OUT> | StringSchemaTyped;
4
4
  /**
5
5
  * IN - value before validation/conversion
6
6
  * OUT - value after validation/conversion (can be different due to conversion, stripping, etc)
@@ -16,6 +16,14 @@ export declare function objectSchema<IN, OUT = IN>(schema?: {
16
16
  export declare function oneOfSchema<T = any>(...schemas: AnySchemaTyped<any>[]): AlternativesSchemaTyped<T>;
17
17
  export declare const anySchema: import("joi").AnySchema;
18
18
  export declare const anyObjectSchema: import("joi").ObjectSchema<any>;
19
+ export declare const BASE62_REGEX: RegExp;
20
+ export declare const BASE64_REGEX: RegExp;
21
+ export declare const BASE64URL_REGEX: RegExp;
22
+ export declare const base62Schema: import("./string.extensions").ExtendedStringSchema;
23
+ export declare const base64Schema: import("./string.extensions").ExtendedStringSchema;
24
+ export declare const base64UrlSchema: import("./string.extensions").ExtendedStringSchema;
25
+ export declare const JWT_REGEX: RegExp;
26
+ export declare const jwtSchema: import("./string.extensions").ExtendedStringSchema;
19
27
  /**
20
28
  * [a-zA-Z0-9_]*
21
29
  * 6-64 length
@@ -24,13 +32,10 @@ export declare const idSchema: import("./string.extensions").ExtendedStringSchem
24
32
  export declare const idBase62Schema: import("./string.extensions").ExtendedStringSchema;
25
33
  export declare const idBase64Schema: import("./string.extensions").ExtendedStringSchema;
26
34
  export declare const idBase64UrlSchema: import("./string.extensions").ExtendedStringSchema;
27
- export declare const base62Schema: import("./string.extensions").ExtendedStringSchema;
28
- export declare const base64Schema: import("./string.extensions").ExtendedStringSchema;
29
- export declare const base64UrlSchema: import("./string.extensions").ExtendedStringSchema;
30
35
  /**
31
36
  * `_` should NOT be allowed to be able to use slug-ids as part of natural ids with `_` separator.
32
37
  */
33
- export declare const SLUG_PATTERN: RegExp;
38
+ export declare const SLUG_REGEX: RegExp;
34
39
  /**
35
40
  * "Slug" - a valid URL, filename, etc.
36
41
  */
@@ -59,7 +64,7 @@ export declare const emailSchema: import("./string.extensions").ExtendedStringSc
59
64
  /**
60
65
  * Pattern is simplified for our use, it's not a canonical SemVer.
61
66
  */
62
- export declare const SEM_VER_PATTERN: RegExp;
67
+ export declare const SEM_VER_REGEX: RegExp;
63
68
  export declare const semVerSchema: import("./string.extensions").ExtendedStringSchema;
64
69
  export declare const userAgentSchema: import("./string.extensions").ExtendedStringSchema;
65
70
  export declare const utcOffsetSchema: import("./number.extensions").ExtendedNumberSchema;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.savedDBEntitySchema = exports.baseDBEntitySchema = exports.ipAddressSchema = exports.utcOffsetSchema = exports.userAgentSchema = exports.semVerSchema = exports.SEM_VER_PATTERN = exports.emailSchema = exports.verSchema = exports.unixTimestampMillis2000Schema = exports.unixTimestampMillisSchema = exports.unixTimestamp2000Schema = exports.unixTimestampSchema = exports.slugSchema = exports.SLUG_PATTERN = exports.base64UrlSchema = exports.base64Schema = exports.base62Schema = exports.idBase64UrlSchema = exports.idBase64Schema = exports.idBase62Schema = exports.idSchema = exports.anyObjectSchema = exports.anySchema = exports.oneOfSchema = exports.objectSchema = exports.arraySchema = exports.urlSchema = exports.binarySchema = exports.dateStringSchema = exports.percentageSchema = exports.integerSchema = exports.numberSchema = exports.stringSchema = exports.booleanDefaultToFalseSchema = exports.booleanSchema = void 0;
3
+ exports.savedDBEntitySchema = exports.baseDBEntitySchema = exports.ipAddressSchema = exports.utcOffsetSchema = exports.userAgentSchema = exports.semVerSchema = exports.SEM_VER_REGEX = exports.emailSchema = exports.verSchema = exports.unixTimestampMillis2000Schema = exports.unixTimestampMillisSchema = exports.unixTimestamp2000Schema = exports.unixTimestampSchema = exports.slugSchema = exports.SLUG_REGEX = exports.idBase64UrlSchema = exports.idBase64Schema = exports.idBase62Schema = exports.idSchema = exports.jwtSchema = exports.JWT_REGEX = exports.base64UrlSchema = exports.base64Schema = exports.base62Schema = exports.BASE64URL_REGEX = exports.BASE64_REGEX = exports.BASE62_REGEX = exports.anyObjectSchema = exports.anySchema = exports.oneOfSchema = exports.objectSchema = exports.arraySchema = exports.urlSchema = exports.binarySchema = exports.dateStringSchema = exports.percentageSchema = exports.integerSchema = exports.numberSchema = exports.stringSchema = exports.booleanDefaultToFalseSchema = exports.booleanSchema = void 0;
4
4
  const joi_extensions_1 = require("./joi.extensions");
5
5
  exports.booleanSchema = joi_extensions_1.Joi.boolean();
6
6
  exports.booleanDefaultToFalseSchema = joi_extensions_1.Joi.boolean().default(false);
@@ -26,26 +26,31 @@ function oneOfSchema(...schemas) {
26
26
  exports.oneOfSchema = oneOfSchema;
27
27
  exports.anySchema = joi_extensions_1.Joi.any();
28
28
  exports.anyObjectSchema = joi_extensions_1.Joi.object().options({ stripUnknown: false });
29
+ exports.BASE62_REGEX = /^[a-zA-Z0-9]+$/;
30
+ exports.BASE64_REGEX = /^[A-Za-z0-9+/]+={0,2}$/;
31
+ exports.BASE64URL_REGEX = /^[\w-/]+$/;
32
+ exports.base62Schema = exports.stringSchema.regex(exports.BASE62_REGEX);
33
+ exports.base64Schema = exports.stringSchema.regex(exports.BASE64_REGEX);
34
+ exports.base64UrlSchema = exports.stringSchema.regex(exports.BASE64URL_REGEX);
35
+ exports.JWT_REGEX = /^[\w-]+\.[\w-]+\.[\w-]+$/;
36
+ exports.jwtSchema = exports.stringSchema.regex(exports.JWT_REGEX);
29
37
  // 1g498efj5sder3324zer
30
38
  /**
31
39
  * [a-zA-Z0-9_]*
32
40
  * 6-64 length
33
41
  */
34
42
  exports.idSchema = exports.stringSchema.regex(/^[a-zA-Z0-9_]{6,64}$/);
35
- exports.idBase62Schema = exports.stringSchema.regex(/^[a-zA-Z0-9]{8,64}$/);
36
- exports.idBase64Schema = exports.stringSchema.regex(/^[a-zA-Z0-9+/]{8,64}$/);
37
- exports.idBase64UrlSchema = exports.stringSchema.regex(/^[a-zA-Z0-9-_]{8,64}$/);
38
- exports.base62Schema = exports.stringSchema.regex(/^[a-zA-Z0-9]+$/);
39
- exports.base64Schema = exports.stringSchema.regex(/^[a-zA-Z0-9+/]+$/);
40
- exports.base64UrlSchema = exports.stringSchema.regex(/^[a-zA-Z0-9-_]+$/);
43
+ exports.idBase62Schema = exports.base62Schema.min(8).max(64);
44
+ exports.idBase64Schema = exports.base64Schema.min(8).max(64);
45
+ exports.idBase64UrlSchema = exports.base64UrlSchema.min(8).max(64);
41
46
  /**
42
47
  * `_` should NOT be allowed to be able to use slug-ids as part of natural ids with `_` separator.
43
48
  */
44
- exports.SLUG_PATTERN = /^[a-z0-9-]*$/;
49
+ exports.SLUG_REGEX = /^[a-z0-9-]*$/;
45
50
  /**
46
51
  * "Slug" - a valid URL, filename, etc.
47
52
  */
48
- exports.slugSchema = exports.stringSchema.regex(/^[a-z0-9-_]{1,255}$/);
53
+ exports.slugSchema = exports.stringSchema.regex(exports.SLUG_REGEX).min(1).max(255);
49
54
  const TS_2500 = 16725225600; // 2500-01-01
50
55
  const TS_2000 = 946684800; // 2000-01-01
51
56
  /**
@@ -79,8 +84,8 @@ exports.emailSchema = exports.stringSchema.email().lowercase();
79
84
  /**
80
85
  * Pattern is simplified for our use, it's not a canonical SemVer.
81
86
  */
82
- exports.SEM_VER_PATTERN = /^[0-9]+\.[0-9]+\.[0-9]+$/;
83
- exports.semVerSchema = exports.stringSchema.regex(exports.SEM_VER_PATTERN);
87
+ exports.SEM_VER_REGEX = /^[0-9]+\.[0-9]+\.[0-9]+$/;
88
+ exports.semVerSchema = exports.stringSchema.regex(exports.SEM_VER_REGEX);
84
89
  // todo: .error(() => 'should be SemVer')
85
90
  exports.userAgentSchema = exports.stringSchema
86
91
  .min(5) // I've seen UA of `Android` (7 characters)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@naturalcycles/nodejs-lib",
3
- "version": "12.79.0",
3
+ "version": "12.80.1",
4
4
  "scripts": {
5
5
  "prepare": "husky install",
6
6
  "docs-serve": "vuepress dev docs",
@@ -8,24 +8,27 @@ export function readableMap<IN, OUT>(
8
8
  ): ReadableTyped<OUT> {
9
9
  let i = -1
10
10
 
11
- // todo: check if we need to handle errors somehow specifically
12
- return readable.pipe(
13
- new Transform({
14
- objectMode: true,
15
- async transform(chunk, _enc, cb) {
16
- try {
17
- const r = await mapper(chunk, ++i)
18
- if (r === SKIP) {
19
- cb()
20
- } else {
21
- // _assert(r !== END, `readableMap END not supported`)
22
- cb(null, r)
11
+ const stream: ReadableTyped<OUT> = readable
12
+ .on('error', err => stream.emit('error', err))
13
+ .pipe(
14
+ new Transform({
15
+ objectMode: true,
16
+ async transform(chunk, _enc, cb) {
17
+ try {
18
+ const r = await mapper(chunk, ++i)
19
+ if (r === SKIP) {
20
+ cb()
21
+ } else {
22
+ // _assert(r !== END, `readableMap END not supported`)
23
+ cb(null, r)
24
+ }
25
+ } catch (err) {
26
+ console.error(err)
27
+ cb(err as Error)
23
28
  }
24
- } catch (err) {
25
- console.error(err)
26
- cb(err as Error)
27
- }
28
- },
29
- }),
30
- )
29
+ },
30
+ }),
31
+ )
32
+
33
+ return stream
31
34
  }
@@ -40,6 +40,16 @@ export function oneOfSchema<T = any>(
40
40
  export const anySchema = Joi.any()
41
41
  export const anyObjectSchema = Joi.object().options({ stripUnknown: false })
42
42
 
43
+ export const BASE62_REGEX = /^[a-zA-Z0-9]+$/
44
+ export const BASE64_REGEX = /^[A-Za-z0-9+/]+={0,2}$/
45
+ export const BASE64URL_REGEX = /^[\w-/]+$/
46
+ export const base62Schema = stringSchema.regex(BASE62_REGEX)
47
+ export const base64Schema = stringSchema.regex(BASE64_REGEX)
48
+ export const base64UrlSchema = stringSchema.regex(BASE64URL_REGEX)
49
+
50
+ export const JWT_REGEX = /^[\w-]+\.[\w-]+\.[\w-]+$/
51
+ export const jwtSchema = stringSchema.regex(JWT_REGEX)
52
+
43
53
  // 1g498efj5sder3324zer
44
54
  /**
45
55
  * [a-zA-Z0-9_]*
@@ -47,23 +57,19 @@ export const anyObjectSchema = Joi.object().options({ stripUnknown: false })
47
57
  */
48
58
  export const idSchema = stringSchema.regex(/^[a-zA-Z0-9_]{6,64}$/)
49
59
 
50
- export const idBase62Schema = stringSchema.regex(/^[a-zA-Z0-9]{8,64}$/)
51
- export const idBase64Schema = stringSchema.regex(/^[a-zA-Z0-9+/]{8,64}$/)
52
- export const idBase64UrlSchema = stringSchema.regex(/^[a-zA-Z0-9-_]{8,64}$/)
53
-
54
- export const base62Schema = stringSchema.regex(/^[a-zA-Z0-9]+$/)
55
- export const base64Schema = stringSchema.regex(/^[a-zA-Z0-9+/]+$/)
56
- export const base64UrlSchema = stringSchema.regex(/^[a-zA-Z0-9-_]+$/)
60
+ export const idBase62Schema = base62Schema.min(8).max(64)
61
+ export const idBase64Schema = base64Schema.min(8).max(64)
62
+ export const idBase64UrlSchema = base64UrlSchema.min(8).max(64)
57
63
 
58
64
  /**
59
65
  * `_` should NOT be allowed to be able to use slug-ids as part of natural ids with `_` separator.
60
66
  */
61
- export const SLUG_PATTERN = /^[a-z0-9-]*$/
67
+ export const SLUG_REGEX = /^[a-z0-9-]*$/
62
68
 
63
69
  /**
64
70
  * "Slug" - a valid URL, filename, etc.
65
71
  */
66
- export const slugSchema = stringSchema.regex(/^[a-z0-9-_]{1,255}$/)
72
+ export const slugSchema = stringSchema.regex(SLUG_REGEX).min(1).max(255)
67
73
 
68
74
  const TS_2500 = 16725225600 // 2500-01-01
69
75
  const TS_2000 = 946684800 // 2000-01-01
@@ -102,8 +108,8 @@ export const emailSchema = stringSchema.email().lowercase()
102
108
  /**
103
109
  * Pattern is simplified for our use, it's not a canonical SemVer.
104
110
  */
105
- export const SEM_VER_PATTERN = /^[0-9]+\.[0-9]+\.[0-9]+$/
106
- export const semVerSchema = stringSchema.regex(SEM_VER_PATTERN)
111
+ export const SEM_VER_REGEX = /^[0-9]+\.[0-9]+\.[0-9]+$/
112
+ export const semVerSchema = stringSchema.regex(SEM_VER_REGEX)
107
113
  // todo: .error(() => 'should be SemVer')
108
114
 
109
115
  export const userAgentSchema = stringSchema