@naturalcycles/nodejs-lib 12.78.0 → 12.80.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.
package/dist/index.d.ts CHANGED
@@ -1,35 +1,36 @@
1
1
  import Ajv from 'ajv';
2
2
  import * as fastGlob from 'fast-glob';
3
- import { Options as FastGlobOptions } from 'fast-glob';
3
+ import type { Options as FastGlobOptions } from 'fast-glob';
4
4
  import * as globby from 'globby';
5
- import { GlobbyOptions } from 'globby';
5
+ import type { GlobbyOptions } from 'globby';
6
6
  import { RequestError, TimeoutError } from 'got';
7
7
  import type { AfterResponseHook, BeforeErrorHook, BeforeRequestHook, Got } from 'got';
8
- import { AnySchema, ValidationErrorItem } from 'joi';
9
- import { _chunkBuffer } from './buffer/buffer.util';
10
- import { tableDiff, TableDiffOptions } from './diff/tableDiff';
8
+ import type { AnySchema, ValidationErrorItem } from 'joi';
9
+ export * from './buffer/buffer.util';
10
+ export * from './diff/tableDiff';
11
11
  export * from './got/getGot';
12
- import { GetGotOptions } from './got/got.model';
12
+ export * from './got/got.model';
13
13
  export * from './infra/process.util';
14
- import { Debug, IDebug, IDebugger } from './log/debug';
14
+ export * from './log/debug';
15
15
  export * from './security/hash.util';
16
16
  export * from './security/crypto.util';
17
17
  export * from './security/id.util';
18
+ export * from './security/nanoid';
18
19
  export * from './security/secret.util';
19
20
  export * from './colors/colors';
20
21
  export * from './log/log.util';
21
- import { slackDefaultMessagePrefixHook, SlackService } from './slack/slack.service';
22
- import { SlackApiBody, SlackMessage, SlackMessagePrefixHook, SlackMessageProps, SlackServiceCfg } from './slack/slack.service.model';
23
- import { NDJsonStats } from './stream/ndjson/ndjson.model';
22
+ export * from './slack/slack.service';
23
+ export * from './slack/slack.service.model';
24
+ export * from './stream/ndjson/ndjson.model';
24
25
  export * from './stream/ndjson/ndJsonFileRead';
25
26
  export * from './stream/ndjson/ndJsonFileWrite';
26
27
  export * from './stream/ndjson/ndjsonMap';
27
- import { ndjsonStreamForEach, NDJSONStreamForEachOptions } from './stream/ndjson/ndjsonStreamForEach';
28
- import { pipelineFromNDJsonFile, PipelineFromNDJsonFileOptions } from './stream/ndjson/pipelineFromNDJsonFile';
29
- import { pipelineToNDJsonFile, PipelineToNDJsonFileOptions } from './stream/ndjson/pipelineToNDJsonFile';
30
- import { streamToNDJsonFile } from './stream/ndjson/streamToNDJsonFile';
31
- import { bufferReviver, transformJsonParse, TransformJsonParseOptions } from './stream/ndjson/transformJsonParse';
32
- import { transformToNDJson, TransformToNDJsonOptions } from './stream/ndjson/transformToNDJson';
28
+ export * from './stream/ndjson/ndjsonStreamForEach';
29
+ export * from './stream/ndjson/pipelineFromNDJsonFile';
30
+ export * from './stream/ndjson/pipelineToNDJsonFile';
31
+ export * from './stream/ndjson/streamToNDJsonFile';
32
+ export * from './stream/ndjson/transformJsonParse';
33
+ export * from './stream/ndjson/transformToNDJson';
33
34
  export * from './stream/pipeline/pipeline';
34
35
  export * from './stream/readable/readableCreate';
35
36
  export * from './stream/readable/readableForEach';
@@ -37,39 +38,39 @@ export * from './stream/readable/readableFromArray';
37
38
  export * from './stream/readable/readableMap';
38
39
  export * from './stream/readable/readableMapToArray';
39
40
  export * from './stream/readable/readableToArray';
40
- import { ReadableTyped, TransformOptions, TransformTyped, WritableTyped } from './stream/stream.model';
41
+ export * from './stream/stream.model';
41
42
  export * from './stream/transform/transformBuffer';
42
43
  export * from './stream/transform/transformFilter';
43
44
  export * from './stream/transform/transformLimit';
44
45
  export * from './stream/transform/transformLogProgress';
45
- import { transformMap, TransformMapOptions } from './stream/transform/transformMap';
46
+ export * from './stream/transform/transformMap';
46
47
  export * from './stream/transform/transformMapSimple';
47
48
  export * from './stream/transform/transformNoOp';
48
- import { transformMapSync, TransformMapSyncOptions } from './stream/transform/transformMapSync';
49
+ export * from './stream/transform/transformMapSync';
49
50
  export * from './stream/transform/transformSplit';
50
51
  export * from './stream/transform/transformTap';
51
52
  export * from './stream/transform/transformToArray';
52
53
  export * from './stream/transform/transformToString';
53
- import { BaseWorkerClass, WorkerClassInterface } from './stream/transform/worker/baseWorkerClass';
54
- import { transformMultiThreaded, TransformMultiThreadedOptions } from './stream/transform/worker/transformMultiThreaded';
55
- import { WorkerInput, WorkerOutput } from './stream/transform/worker/transformMultiThreaded.model';
54
+ export * from './stream/transform/worker/baseWorkerClass';
55
+ export * from './stream/transform/worker/transformMultiThreaded';
56
+ export * from './stream/transform/worker/transformMultiThreaded.model';
56
57
  export * from './stream/writable/writableForEach';
57
58
  export * from './stream/writable/writableFork';
58
59
  export * from './stream/writable/writablePushToArray';
59
60
  export * from './stream/writable/writableVoid';
60
- import { inspectAny, InspectAnyOptions, inspectAnyStringifyFn } from './string/inspectAny';
61
+ export * from './string/inspectAny';
61
62
  export * from './util/env.util';
62
63
  export * from './util/lruMemoCache';
63
64
  export * from './util/zip.util';
64
- import { readAjvSchemas, readJsonSchemas } from './validation/ajv/ajv.util';
65
- import { AjvSchema, AjvSchemaCfg, AjvValidationOptions } from './validation/ajv/ajvSchema';
66
- import { AjvValidationError, AjvValidationErrorData } from './validation/ajv/ajvValidationError';
65
+ export * from './validation/ajv/ajv.util';
66
+ export * from './validation/ajv/ajvSchema';
67
+ export * from './validation/ajv/ajvValidationError';
67
68
  export * from './validation/ajv/getAjv';
68
- import { ExtendedJoi, Joi } from './validation/joi/joi.extensions';
69
- import { AnySchemaTyped, ArraySchemaTyped, BooleanSchemaTyped, NumberSchemaTyped, ObjectSchemaTyped, SchemaTyped, StringSchemaTyped } from './validation/joi/joi.model';
69
+ export * from './validation/joi/joi.extensions';
70
+ export * from './validation/joi/joi.model';
70
71
  export * from './validation/joi/joi.shared.schemas';
71
- import { JoiValidationError, JoiValidationErrorData } from './validation/joi/joi.validation.error';
72
- import { convert, getValidationResult, isValid, JoiValidationResult, undefinedIfInvalid, validate } from './validation/joi/joi.validation.util';
73
- import { runScript, RunScriptOptions } from './script';
74
- export type { GlobbyOptions, FastGlobOptions, RunScriptOptions, JoiValidationErrorData, JoiValidationResult, ValidationErrorItem, ExtendedJoi, SchemaTyped, AnySchema, AnySchemaTyped, ArraySchemaTyped, BooleanSchemaTyped, NumberSchemaTyped, ObjectSchemaTyped, StringSchemaTyped, IDebug, IDebugger, SlackServiceCfg, SlackMessage, SlackMessageProps, SlackApiBody, SlackMessagePrefixHook, ReadableTyped, WritableTyped, TransformTyped, PipelineFromNDJsonFileOptions, PipelineToNDJsonFileOptions, TransformJsonParseOptions, TransformToNDJsonOptions, TransformMapOptions, TransformMapSyncOptions, NDJSONStreamForEachOptions, TransformOptions, TransformMultiThreadedOptions, WorkerClassInterface, WorkerInput, WorkerOutput, TableDiffOptions, InspectAnyOptions, Got, GetGotOptions, AfterResponseHook, BeforeErrorHook, BeforeRequestHook, AjvValidationOptions, AjvSchemaCfg, AjvValidationErrorData, };
75
- export { globby, fastGlob, JoiValidationError, validate, getValidationResult, isValid, undefinedIfInvalid, convert, Joi, Debug, SlackService, slackDefaultMessagePrefixHook, ndjsonStreamForEach, pipelineFromNDJsonFile, pipelineToNDJsonFile, NDJsonStats, streamToNDJsonFile, transformJsonParse, bufferReviver, transformToNDJson, transformMap, transformMapSync, transformMultiThreaded, BaseWorkerClass, tableDiff, inspectAny, inspectAnyStringifyFn, RequestError, TimeoutError, _chunkBuffer, Ajv, AjvSchema, AjvValidationError, readJsonSchemas, readAjvSchemas, runScript, };
72
+ export * from './validation/joi/joi.validation.error';
73
+ export * from './validation/joi/joi.validation.util';
74
+ export * from './script';
75
+ export type { GlobbyOptions, FastGlobOptions, ValidationErrorItem, AnySchema, Got, AfterResponseHook, BeforeErrorHook, BeforeRequestHook, };
76
+ export { globby, fastGlob, RequestError, TimeoutError, Ajv };
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.runScript = exports.readAjvSchemas = exports.readJsonSchemas = exports.AjvValidationError = exports.AjvSchema = exports.Ajv = exports._chunkBuffer = exports.TimeoutError = exports.RequestError = exports.inspectAnyStringifyFn = exports.inspectAny = exports.tableDiff = exports.BaseWorkerClass = exports.transformMultiThreaded = exports.transformMapSync = exports.transformMap = exports.transformToNDJson = exports.bufferReviver = exports.transformJsonParse = exports.streamToNDJsonFile = exports.NDJsonStats = exports.pipelineToNDJsonFile = exports.pipelineFromNDJsonFile = exports.ndjsonStreamForEach = exports.slackDefaultMessagePrefixHook = exports.SlackService = exports.Debug = exports.Joi = exports.convert = exports.undefinedIfInvalid = exports.isValid = exports.getValidationResult = exports.validate = exports.JoiValidationError = exports.fastGlob = exports.globby = void 0;
3
+ exports.Ajv = exports.TimeoutError = exports.RequestError = exports.fastGlob = exports.globby = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const ajv_1 = require("ajv");
6
6
  exports.Ajv = ajv_1.default;
@@ -11,41 +11,31 @@ exports.globby = globby;
11
11
  const got_1 = require("got");
12
12
  Object.defineProperty(exports, "RequestError", { enumerable: true, get: function () { return got_1.RequestError; } });
13
13
  Object.defineProperty(exports, "TimeoutError", { enumerable: true, get: function () { return got_1.TimeoutError; } });
14
- const buffer_util_1 = require("./buffer/buffer.util");
15
- Object.defineProperty(exports, "_chunkBuffer", { enumerable: true, get: function () { return buffer_util_1._chunkBuffer; } });
16
- const tableDiff_1 = require("./diff/tableDiff");
17
- Object.defineProperty(exports, "tableDiff", { enumerable: true, get: function () { return tableDiff_1.tableDiff; } });
14
+ tslib_1.__exportStar(require("./buffer/buffer.util"), exports);
15
+ tslib_1.__exportStar(require("./diff/tableDiff"), exports);
18
16
  tslib_1.__exportStar(require("./got/getGot"), exports);
17
+ tslib_1.__exportStar(require("./got/got.model"), exports);
19
18
  tslib_1.__exportStar(require("./infra/process.util"), exports);
20
- const debug_1 = require("./log/debug");
21
- Object.defineProperty(exports, "Debug", { enumerable: true, get: function () { return debug_1.Debug; } });
19
+ tslib_1.__exportStar(require("./log/debug"), exports);
22
20
  tslib_1.__exportStar(require("./security/hash.util"), exports);
23
21
  tslib_1.__exportStar(require("./security/crypto.util"), exports);
24
22
  tslib_1.__exportStar(require("./security/id.util"), exports);
23
+ tslib_1.__exportStar(require("./security/nanoid"), exports);
25
24
  tslib_1.__exportStar(require("./security/secret.util"), exports);
26
25
  tslib_1.__exportStar(require("./colors/colors"), exports);
27
26
  tslib_1.__exportStar(require("./log/log.util"), exports);
28
- const slack_service_1 = require("./slack/slack.service");
29
- Object.defineProperty(exports, "slackDefaultMessagePrefixHook", { enumerable: true, get: function () { return slack_service_1.slackDefaultMessagePrefixHook; } });
30
- Object.defineProperty(exports, "SlackService", { enumerable: true, get: function () { return slack_service_1.SlackService; } });
31
- const ndjson_model_1 = require("./stream/ndjson/ndjson.model");
32
- Object.defineProperty(exports, "NDJsonStats", { enumerable: true, get: function () { return ndjson_model_1.NDJsonStats; } });
27
+ tslib_1.__exportStar(require("./slack/slack.service"), exports);
28
+ tslib_1.__exportStar(require("./slack/slack.service.model"), exports);
29
+ tslib_1.__exportStar(require("./stream/ndjson/ndjson.model"), exports);
33
30
  tslib_1.__exportStar(require("./stream/ndjson/ndJsonFileRead"), exports);
34
31
  tslib_1.__exportStar(require("./stream/ndjson/ndJsonFileWrite"), exports);
35
32
  tslib_1.__exportStar(require("./stream/ndjson/ndjsonMap"), exports);
36
- const ndjsonStreamForEach_1 = require("./stream/ndjson/ndjsonStreamForEach");
37
- Object.defineProperty(exports, "ndjsonStreamForEach", { enumerable: true, get: function () { return ndjsonStreamForEach_1.ndjsonStreamForEach; } });
38
- const pipelineFromNDJsonFile_1 = require("./stream/ndjson/pipelineFromNDJsonFile");
39
- Object.defineProperty(exports, "pipelineFromNDJsonFile", { enumerable: true, get: function () { return pipelineFromNDJsonFile_1.pipelineFromNDJsonFile; } });
40
- const pipelineToNDJsonFile_1 = require("./stream/ndjson/pipelineToNDJsonFile");
41
- Object.defineProperty(exports, "pipelineToNDJsonFile", { enumerable: true, get: function () { return pipelineToNDJsonFile_1.pipelineToNDJsonFile; } });
42
- const streamToNDJsonFile_1 = require("./stream/ndjson/streamToNDJsonFile");
43
- Object.defineProperty(exports, "streamToNDJsonFile", { enumerable: true, get: function () { return streamToNDJsonFile_1.streamToNDJsonFile; } });
44
- const transformJsonParse_1 = require("./stream/ndjson/transformJsonParse");
45
- Object.defineProperty(exports, "bufferReviver", { enumerable: true, get: function () { return transformJsonParse_1.bufferReviver; } });
46
- Object.defineProperty(exports, "transformJsonParse", { enumerable: true, get: function () { return transformJsonParse_1.transformJsonParse; } });
47
- const transformToNDJson_1 = require("./stream/ndjson/transformToNDJson");
48
- Object.defineProperty(exports, "transformToNDJson", { enumerable: true, get: function () { return transformToNDJson_1.transformToNDJson; } });
33
+ tslib_1.__exportStar(require("./stream/ndjson/ndjsonStreamForEach"), exports);
34
+ tslib_1.__exportStar(require("./stream/ndjson/pipelineFromNDJsonFile"), exports);
35
+ tslib_1.__exportStar(require("./stream/ndjson/pipelineToNDJsonFile"), exports);
36
+ tslib_1.__exportStar(require("./stream/ndjson/streamToNDJsonFile"), exports);
37
+ tslib_1.__exportStar(require("./stream/ndjson/transformJsonParse"), exports);
38
+ tslib_1.__exportStar(require("./stream/ndjson/transformToNDJson"), exports);
49
39
  tslib_1.__exportStar(require("./stream/pipeline/pipeline"), exports);
50
40
  tslib_1.__exportStar(require("./stream/readable/readableCreate"), exports);
51
41
  tslib_1.__exportStar(require("./stream/readable/readableForEach"), exports);
@@ -53,52 +43,37 @@ tslib_1.__exportStar(require("./stream/readable/readableFromArray"), exports);
53
43
  tslib_1.__exportStar(require("./stream/readable/readableMap"), exports);
54
44
  tslib_1.__exportStar(require("./stream/readable/readableMapToArray"), exports);
55
45
  tslib_1.__exportStar(require("./stream/readable/readableToArray"), exports);
46
+ tslib_1.__exportStar(require("./stream/stream.model"), exports);
56
47
  tslib_1.__exportStar(require("./stream/transform/transformBuffer"), exports);
57
48
  tslib_1.__exportStar(require("./stream/transform/transformFilter"), exports);
58
49
  tslib_1.__exportStar(require("./stream/transform/transformLimit"), exports);
59
50
  tslib_1.__exportStar(require("./stream/transform/transformLogProgress"), exports);
60
- const transformMap_1 = require("./stream/transform/transformMap");
61
- Object.defineProperty(exports, "transformMap", { enumerable: true, get: function () { return transformMap_1.transformMap; } });
51
+ tslib_1.__exportStar(require("./stream/transform/transformMap"), exports);
62
52
  tslib_1.__exportStar(require("./stream/transform/transformMapSimple"), exports);
63
53
  tslib_1.__exportStar(require("./stream/transform/transformNoOp"), exports);
64
- const transformMapSync_1 = require("./stream/transform/transformMapSync");
65
- Object.defineProperty(exports, "transformMapSync", { enumerable: true, get: function () { return transformMapSync_1.transformMapSync; } });
54
+ tslib_1.__exportStar(require("./stream/transform/transformMapSync"), exports);
66
55
  tslib_1.__exportStar(require("./stream/transform/transformSplit"), exports);
67
56
  tslib_1.__exportStar(require("./stream/transform/transformTap"), exports);
68
57
  tslib_1.__exportStar(require("./stream/transform/transformToArray"), exports);
69
58
  tslib_1.__exportStar(require("./stream/transform/transformToString"), exports);
70
- const baseWorkerClass_1 = require("./stream/transform/worker/baseWorkerClass");
71
- Object.defineProperty(exports, "BaseWorkerClass", { enumerable: true, get: function () { return baseWorkerClass_1.BaseWorkerClass; } });
72
- const transformMultiThreaded_1 = require("./stream/transform/worker/transformMultiThreaded");
73
- Object.defineProperty(exports, "transformMultiThreaded", { enumerable: true, get: function () { return transformMultiThreaded_1.transformMultiThreaded; } });
59
+ tslib_1.__exportStar(require("./stream/transform/worker/baseWorkerClass"), exports);
60
+ tslib_1.__exportStar(require("./stream/transform/worker/transformMultiThreaded"), exports);
61
+ tslib_1.__exportStar(require("./stream/transform/worker/transformMultiThreaded.model"), exports);
74
62
  tslib_1.__exportStar(require("./stream/writable/writableForEach"), exports);
75
63
  tslib_1.__exportStar(require("./stream/writable/writableFork"), exports);
76
64
  tslib_1.__exportStar(require("./stream/writable/writablePushToArray"), exports);
77
65
  tslib_1.__exportStar(require("./stream/writable/writableVoid"), exports);
78
- const inspectAny_1 = require("./string/inspectAny");
79
- Object.defineProperty(exports, "inspectAny", { enumerable: true, get: function () { return inspectAny_1.inspectAny; } });
80
- Object.defineProperty(exports, "inspectAnyStringifyFn", { enumerable: true, get: function () { return inspectAny_1.inspectAnyStringifyFn; } });
66
+ tslib_1.__exportStar(require("./string/inspectAny"), exports);
81
67
  tslib_1.__exportStar(require("./util/env.util"), exports);
82
68
  tslib_1.__exportStar(require("./util/lruMemoCache"), exports);
83
69
  tslib_1.__exportStar(require("./util/zip.util"), exports);
84
- const ajv_util_1 = require("./validation/ajv/ajv.util");
85
- Object.defineProperty(exports, "readAjvSchemas", { enumerable: true, get: function () { return ajv_util_1.readAjvSchemas; } });
86
- Object.defineProperty(exports, "readJsonSchemas", { enumerable: true, get: function () { return ajv_util_1.readJsonSchemas; } });
87
- const ajvSchema_1 = require("./validation/ajv/ajvSchema");
88
- Object.defineProperty(exports, "AjvSchema", { enumerable: true, get: function () { return ajvSchema_1.AjvSchema; } });
89
- const ajvValidationError_1 = require("./validation/ajv/ajvValidationError");
90
- Object.defineProperty(exports, "AjvValidationError", { enumerable: true, get: function () { return ajvValidationError_1.AjvValidationError; } });
70
+ tslib_1.__exportStar(require("./validation/ajv/ajv.util"), exports);
71
+ tslib_1.__exportStar(require("./validation/ajv/ajvSchema"), exports);
72
+ tslib_1.__exportStar(require("./validation/ajv/ajvValidationError"), exports);
91
73
  tslib_1.__exportStar(require("./validation/ajv/getAjv"), exports);
92
- const joi_extensions_1 = require("./validation/joi/joi.extensions");
93
- Object.defineProperty(exports, "Joi", { enumerable: true, get: function () { return joi_extensions_1.Joi; } });
74
+ tslib_1.__exportStar(require("./validation/joi/joi.extensions"), exports);
75
+ tslib_1.__exportStar(require("./validation/joi/joi.model"), exports);
94
76
  tslib_1.__exportStar(require("./validation/joi/joi.shared.schemas"), exports);
95
- const joi_validation_error_1 = require("./validation/joi/joi.validation.error");
96
- Object.defineProperty(exports, "JoiValidationError", { enumerable: true, get: function () { return joi_validation_error_1.JoiValidationError; } });
97
- const joi_validation_util_1 = require("./validation/joi/joi.validation.util");
98
- Object.defineProperty(exports, "convert", { enumerable: true, get: function () { return joi_validation_util_1.convert; } });
99
- Object.defineProperty(exports, "getValidationResult", { enumerable: true, get: function () { return joi_validation_util_1.getValidationResult; } });
100
- Object.defineProperty(exports, "isValid", { enumerable: true, get: function () { return joi_validation_util_1.isValid; } });
101
- Object.defineProperty(exports, "undefinedIfInvalid", { enumerable: true, get: function () { return joi_validation_util_1.undefinedIfInvalid; } });
102
- Object.defineProperty(exports, "validate", { enumerable: true, get: function () { return joi_validation_util_1.validate; } });
103
- const script_1 = require("./script");
104
- Object.defineProperty(exports, "runScript", { enumerable: true, get: function () { return script_1.runScript; } });
77
+ tslib_1.__exportStar(require("./validation/joi/joi.validation.error"), exports);
78
+ tslib_1.__exportStar(require("./validation/joi/joi.validation.util"), exports);
79
+ tslib_1.__exportStar(require("./script"), exports);
@@ -1,13 +1,29 @@
1
- export declare const ALPHABET_NUMBER = "0123456789";
2
- export declare const ALPHABET_LOWERCASE = "abcdefghijklmnopqrstuvwxyz";
3
- export declare const ALPHABET_UPPERCASE = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
4
- export declare const ALPHABET_ALPHANUMERIC_LOWERCASE: string;
5
- export declare const ALPHABET_ALPHANUMERIC_UPPERCASE: string;
6
- export declare const ALPHABET_ALPHANUMERIC: string;
7
1
  /**
8
2
  * Generate cryptographically-secure string id.
9
3
  * Powered by `nanoid`.
10
4
  */
11
5
  export declare function stringId(length?: number, alphabet?: string): string;
12
- export declare function stringIdAsync(length?: number, alphabet?: string): Promise<string>;
13
- export declare function stringIdUnsafe(length?: number, alphabet?: string): string;
6
+ /**
7
+ * Generate a string id of Base62 alphabet (same as "alphanumeric": A-Za-z0-9)
8
+ *
9
+ * Length is 16 (non-configurable currently).
10
+ */
11
+ export declare const stringIdBase62: () => string;
12
+ /**
13
+ * Generate a string id of Base64 alphabet: A-Za-z0-9+/
14
+ *
15
+ * Default length is 16.
16
+ * Length should be dividable by 4 (otherwise unexpected length will be produced).
17
+ *
18
+ * Dividable by 4 lengths produce ids with no padding `=` characters, which is optimal.
19
+ */
20
+ export declare function stringIdBase64(size?: number): string;
21
+ /**
22
+ * Generate a string id of Base64url alphabet: A-Za-z0-9-_
23
+ *
24
+ * Default length is 16.
25
+ * Length should be dividable by 4 (otherwise unexpected length will be produced).
26
+ *
27
+ * Base64url always produces strings without a padding character `=`, by design.
28
+ */
29
+ export declare function stringIdBase64Url(size?: number): string;
@@ -1,28 +1,43 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.stringIdUnsafe = exports.stringIdAsync = exports.stringId = exports.ALPHABET_ALPHANUMERIC = exports.ALPHABET_ALPHANUMERIC_UPPERCASE = exports.ALPHABET_ALPHANUMERIC_LOWERCASE = exports.ALPHABET_UPPERCASE = exports.ALPHABET_LOWERCASE = exports.ALPHABET_NUMBER = void 0;
4
- const nanoid_1 = require("nanoid");
5
- const async_1 = require("nanoid/async");
6
- const non_secure_1 = require("nanoid/non-secure");
7
- exports.ALPHABET_NUMBER = '0123456789';
8
- exports.ALPHABET_LOWERCASE = 'abcdefghijklmnopqrstuvwxyz';
9
- exports.ALPHABET_UPPERCASE = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
10
- exports.ALPHABET_ALPHANUMERIC_LOWERCASE = [exports.ALPHABET_NUMBER, exports.ALPHABET_LOWERCASE].join('');
11
- exports.ALPHABET_ALPHANUMERIC_UPPERCASE = [exports.ALPHABET_NUMBER, exports.ALPHABET_UPPERCASE].join('');
12
- exports.ALPHABET_ALPHANUMERIC = [exports.ALPHABET_NUMBER, exports.ALPHABET_LOWERCASE, exports.ALPHABET_UPPERCASE].join('');
3
+ exports.stringIdBase64Url = exports.stringIdBase64 = exports.stringIdBase62 = exports.stringId = void 0;
4
+ const crypto = require("node:crypto");
5
+ const nanoid_1 = require("./nanoid");
13
6
  /**
14
7
  * Generate cryptographically-secure string id.
15
8
  * Powered by `nanoid`.
16
9
  */
17
- function stringId(length = 16, alphabet = exports.ALPHABET_ALPHANUMERIC_LOWERCASE) {
18
- return (0, nanoid_1.customAlphabet)(alphabet, length)();
10
+ function stringId(length = 16, alphabet = nanoid_1.ALPHABET_ALPHANUMERIC_LOWERCASE) {
11
+ return (0, nanoid_1.nanoIdCustomAlphabet)(alphabet, length)();
19
12
  }
20
13
  exports.stringId = stringId;
21
- async function stringIdAsync(length = 16, alphabet = exports.ALPHABET_ALPHANUMERIC_LOWERCASE) {
22
- return await (0, async_1.customAlphabet)(alphabet, length)();
14
+ /**
15
+ * Generate a string id of Base62 alphabet (same as "alphanumeric": A-Za-z0-9)
16
+ *
17
+ * Length is 16 (non-configurable currently).
18
+ */
19
+ exports.stringIdBase62 = (0, nanoid_1.nanoIdCustomAlphabet)(nanoid_1.ALPHABET_ALPHANUMERIC, 16);
20
+ /**
21
+ * Generate a string id of Base64 alphabet: A-Za-z0-9+/
22
+ *
23
+ * Default length is 16.
24
+ * Length should be dividable by 4 (otherwise unexpected length will be produced).
25
+ *
26
+ * Dividable by 4 lengths produce ids with no padding `=` characters, which is optimal.
27
+ */
28
+ function stringIdBase64(size = 16) {
29
+ return crypto.randomBytes(size * 0.75).toString('base64');
23
30
  }
24
- exports.stringIdAsync = stringIdAsync;
25
- function stringIdUnsafe(length = 16, alphabet = exports.ALPHABET_ALPHANUMERIC_LOWERCASE) {
26
- return (0, non_secure_1.customAlphabet)(alphabet, length)();
31
+ exports.stringIdBase64 = stringIdBase64;
32
+ /**
33
+ * Generate a string id of Base64url alphabet: A-Za-z0-9-_
34
+ *
35
+ * Default length is 16.
36
+ * Length should be dividable by 4 (otherwise unexpected length will be produced).
37
+ *
38
+ * Base64url always produces strings without a padding character `=`, by design.
39
+ */
40
+ function stringIdBase64Url(size = 16) {
41
+ return crypto.randomBytes(size * 0.75).toString('base64url');
27
42
  }
28
- exports.stringIdUnsafe = stringIdUnsafe;
43
+ exports.stringIdBase64Url = stringIdBase64Url;
@@ -0,0 +1,10 @@
1
+ export declare const ALPHABET_NUMBER = "0123456789";
2
+ export declare const ALPHABET_LOWERCASE = "abcdefghijklmnopqrstuvwxyz";
3
+ export declare const ALPHABET_UPPERCASE = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
4
+ export declare const ALPHABET_ALPHANUMERIC_LOWERCASE: string;
5
+ export declare const ALPHABET_ALPHANUMERIC_UPPERCASE: string;
6
+ export declare const ALPHABET_ALPHANUMERIC: string;
7
+ export declare const ALPHABET_BASE64: string;
8
+ export declare const ALPHABET_BASE64_URL: string;
9
+ export declare function nanoIdCustomAlphabet(alphabet: string, size?: number): (size?: number) => string;
10
+ export declare function nanoid(size?: number): string;
@@ -0,0 +1,96 @@
1
+ "use strict";
2
+ /*
3
+
4
+ This file is "vendored" from Nanoid, all credit is to Nanoid authors:
5
+ https://github.com/ai/nanoid/
6
+
7
+ */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.nanoid = exports.nanoIdCustomAlphabet = exports.ALPHABET_BASE64_URL = exports.ALPHABET_BASE64 = exports.ALPHABET_ALPHANUMERIC = exports.ALPHABET_ALPHANUMERIC_UPPERCASE = exports.ALPHABET_ALPHANUMERIC_LOWERCASE = exports.ALPHABET_UPPERCASE = exports.ALPHABET_LOWERCASE = exports.ALPHABET_NUMBER = void 0;
10
+ /* eslint-disable */
11
+ const node_crypto_1 = require("node:crypto");
12
+ exports.ALPHABET_NUMBER = '0123456789';
13
+ exports.ALPHABET_LOWERCASE = 'abcdefghijklmnopqrstuvwxyz';
14
+ exports.ALPHABET_UPPERCASE = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
15
+ exports.ALPHABET_ALPHANUMERIC_LOWERCASE = [exports.ALPHABET_NUMBER, exports.ALPHABET_LOWERCASE].join('');
16
+ exports.ALPHABET_ALPHANUMERIC_UPPERCASE = [exports.ALPHABET_NUMBER, exports.ALPHABET_UPPERCASE].join('');
17
+ exports.ALPHABET_ALPHANUMERIC = [exports.ALPHABET_NUMBER, exports.ALPHABET_LOWERCASE, exports.ALPHABET_UPPERCASE].join('');
18
+ exports.ALPHABET_BASE64 = [exports.ALPHABET_ALPHANUMERIC, '+/'].join('');
19
+ exports.ALPHABET_BASE64_URL = [exports.ALPHABET_ALPHANUMERIC, '-_'].join('');
20
+ // It is best to make fewer, larger requests to the crypto module to
21
+ // avoid system call overhead. So, random numbers are generated in a
22
+ // pool. The pool is a Buffer that is larger than the initial random
23
+ // request size by this multiplier. The pool is enlarged if subsequent
24
+ // requests exceed the maximum buffer size.
25
+ const POOL_SIZE_MULTIPLIER = 128;
26
+ let pool;
27
+ let poolOffset;
28
+ function fillPool(bytes) {
29
+ if (!pool || pool.length < bytes) {
30
+ pool = Buffer.allocUnsafe(bytes * POOL_SIZE_MULTIPLIER);
31
+ (0, node_crypto_1.randomFillSync)(pool);
32
+ poolOffset = 0;
33
+ }
34
+ else if (poolOffset + bytes > pool.length) {
35
+ (0, node_crypto_1.randomFillSync)(pool);
36
+ poolOffset = 0;
37
+ }
38
+ poolOffset += bytes;
39
+ }
40
+ function random(bytes) {
41
+ // `-=` convert `bytes` to number to prevent `valueOf` abusing
42
+ fillPool((bytes -= 0));
43
+ return pool.subarray(poolOffset - bytes, poolOffset);
44
+ }
45
+ function customRandom(alphabet, defaultSize, getRandom) {
46
+ // First, a bitmask is necessary to generate the ID. The bitmask makes bytes
47
+ // values closer to the alphabet size. The bitmask calculates the closest
48
+ // `2^31 - 1` number, which exceeds the alphabet size.
49
+ // For example, the bitmask for the alphabet size 30 is 31 (00011111).
50
+ const mask = (2 << (31 - Math.clz32((alphabet.length - 1) | 1))) - 1;
51
+ // Though, the bitmask solution is not perfect since the bytes exceeding
52
+ // the alphabet size are refused. Therefore, to reliably generate the ID,
53
+ // the random bytes redundancy has to be satisfied.
54
+ // Note: every hardware random generator call is performance expensive,
55
+ // because the system call for entropy collection takes a lot of time.
56
+ // So, to avoid additional system calls, extra bytes are requested in advance.
57
+ // Next, a step determines how many random bytes to generate.
58
+ // The number of random bytes gets decided upon the ID size, mask,
59
+ // alphabet size, and magic number 1.6 (using 1.6 peaks at performance
60
+ // according to benchmarks).
61
+ const step = Math.ceil((1.6 * mask * defaultSize) / alphabet.length);
62
+ return (size = defaultSize) => {
63
+ let id = '';
64
+ while (true) {
65
+ const bytes = getRandom(step);
66
+ // A compact alternative for `for (let i = 0; i < step; i++)`.
67
+ let i = step;
68
+ while (i--) {
69
+ // Adding `|| ''` refuses a random byte that exceeds the alphabet size.
70
+ id += alphabet[bytes[i] & mask] || '';
71
+ if (id.length === size)
72
+ return id;
73
+ }
74
+ }
75
+ };
76
+ }
77
+ function nanoIdCustomAlphabet(alphabet, size = 21) {
78
+ return customRandom(alphabet, size, random);
79
+ }
80
+ exports.nanoIdCustomAlphabet = nanoIdCustomAlphabet;
81
+ function nanoid(size = 21) {
82
+ // `-=` convert `size` to number to prevent `valueOf` abusing
83
+ fillPool((size -= 0));
84
+ let id = '';
85
+ // We are reading directly from the random pool to avoid creating new array
86
+ for (let i = poolOffset - size; i < poolOffset; i++) {
87
+ // It is incorrect to use bytes exceeding the alphabet size.
88
+ // The following mask reduces the random byte in the 0-255 value
89
+ // range to the 0-63 value range. Therefore, adding hacks, such
90
+ // as empty string fallback or magic numbers, is unneccessary because
91
+ // the bitmask trims bytes down to the alphabet size.
92
+ id += exports.ALPHABET_BASE64_URL[pool[i] & 63];
93
+ }
94
+ return id;
95
+ }
96
+ exports.nanoid = nanoid;
@@ -16,15 +16,26 @@ 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
22
30
  */
23
31
  export declare const idSchema: import("./string.extensions").ExtendedStringSchema;
32
+ export declare const idBase62Schema: import("./string.extensions").ExtendedStringSchema;
33
+ export declare const idBase64Schema: import("./string.extensions").ExtendedStringSchema;
34
+ export declare const idBase64UrlSchema: import("./string.extensions").ExtendedStringSchema;
24
35
  /**
25
36
  * `_` should NOT be allowed to be able to use slug-ids as part of natural ids with `_` separator.
26
37
  */
27
- export declare const SLUG_PATTERN: RegExp;
38
+ export declare const SLUG_REGEX: RegExp;
28
39
  /**
29
40
  * "Slug" - a valid URL, filename, etc.
30
41
  */
@@ -53,7 +64,7 @@ export declare const emailSchema: import("./string.extensions").ExtendedStringSc
53
64
  /**
54
65
  * Pattern is simplified for our use, it's not a canonical SemVer.
55
66
  */
56
- export declare const SEM_VER_PATTERN: RegExp;
67
+ export declare const SEM_VER_REGEX: RegExp;
57
68
  export declare const semVerSchema: import("./string.extensions").ExtendedStringSchema;
58
69
  export declare const userAgentSchema: import("./string.extensions").ExtendedStringSchema;
59
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.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,20 +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}$/);
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);
35
46
  /**
36
47
  * `_` should NOT be allowed to be able to use slug-ids as part of natural ids with `_` separator.
37
48
  */
38
- exports.SLUG_PATTERN = /^[a-z0-9-]*$/;
49
+ exports.SLUG_REGEX = /^[a-z0-9-]*$/;
39
50
  /**
40
51
  * "Slug" - a valid URL, filename, etc.
41
52
  */
42
- exports.slugSchema = exports.stringSchema.regex(/^[a-z0-9-]{1,255}$/);
53
+ exports.slugSchema = exports.stringSchema.regex(exports.SLUG_REGEX).min(1).max(255);
43
54
  const TS_2500 = 16725225600; // 2500-01-01
44
55
  const TS_2000 = 946684800; // 2000-01-01
45
56
  /**
@@ -73,8 +84,8 @@ exports.emailSchema = exports.stringSchema.email().lowercase();
73
84
  /**
74
85
  * Pattern is simplified for our use, it's not a canonical SemVer.
75
86
  */
76
- exports.SEM_VER_PATTERN = /^[0-9]+\.[0-9]+\.[0-9]+$/;
77
- 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);
78
89
  // todo: .error(() => 'should be SemVer')
79
90
  exports.userAgentSchema = exports.stringSchema
80
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.78.0",
3
+ "version": "12.80.0",
4
4
  "scripts": {
5
5
  "prepare": "husky install",
6
6
  "docs-serve": "vuepress dev docs",
@@ -33,7 +33,6 @@
33
33
  "joi": "17.4.2",
34
34
  "lru-cache": "^7.4.0",
35
35
  "move-file": "^2.0.0",
36
- "nanoid": "^3.0.0",
37
36
  "through2-concurrent": "^2.0.0",
38
37
  "yargs": "^17.0.0"
39
38
  },
package/src/index.ts CHANGED
@@ -1,54 +1,36 @@
1
1
  import Ajv from 'ajv'
2
2
  import * as fastGlob from 'fast-glob'
3
- import { Options as FastGlobOptions } from 'fast-glob'
3
+ import type { Options as FastGlobOptions } from 'fast-glob'
4
4
  import * as globby from 'globby'
5
- import { GlobbyOptions } from 'globby'
5
+ import type { GlobbyOptions } from 'globby'
6
6
  import { RequestError, TimeoutError } from 'got'
7
7
  import type { AfterResponseHook, BeforeErrorHook, BeforeRequestHook, Got } from 'got'
8
- import { AnySchema, ValidationErrorItem } from 'joi'
9
- import { _chunkBuffer } from './buffer/buffer.util'
10
- import { tableDiff, TableDiffOptions } from './diff/tableDiff'
8
+ import type { AnySchema, ValidationErrorItem } from 'joi'
9
+ export * from './buffer/buffer.util'
10
+ export * from './diff/tableDiff'
11
11
  export * from './got/getGot'
12
- import { GetGotOptions } from './got/got.model'
12
+ export * from './got/got.model'
13
13
  export * from './infra/process.util'
14
- import { Debug, IDebug, IDebugger } from './log/debug'
14
+ export * from './log/debug'
15
15
  export * from './security/hash.util'
16
16
  export * from './security/crypto.util'
17
17
  export * from './security/id.util'
18
+ export * from './security/nanoid'
18
19
  export * from './security/secret.util'
19
20
  export * from './colors/colors'
20
21
  export * from './log/log.util'
21
- import { slackDefaultMessagePrefixHook, SlackService } from './slack/slack.service'
22
- import {
23
- SlackApiBody,
24
- SlackMessage,
25
- SlackMessagePrefixHook,
26
- SlackMessageProps,
27
- SlackServiceCfg,
28
- } from './slack/slack.service.model'
29
- import { NDJsonStats } from './stream/ndjson/ndjson.model'
22
+ export * from './slack/slack.service'
23
+ export * from './slack/slack.service.model'
24
+ export * from './stream/ndjson/ndjson.model'
30
25
  export * from './stream/ndjson/ndJsonFileRead'
31
26
  export * from './stream/ndjson/ndJsonFileWrite'
32
27
  export * from './stream/ndjson/ndjsonMap'
33
- import {
34
- ndjsonStreamForEach,
35
- NDJSONStreamForEachOptions,
36
- } from './stream/ndjson/ndjsonStreamForEach'
37
- import {
38
- pipelineFromNDJsonFile,
39
- PipelineFromNDJsonFileOptions,
40
- } from './stream/ndjson/pipelineFromNDJsonFile'
41
- import {
42
- pipelineToNDJsonFile,
43
- PipelineToNDJsonFileOptions,
44
- } from './stream/ndjson/pipelineToNDJsonFile'
45
- import { streamToNDJsonFile } from './stream/ndjson/streamToNDJsonFile'
46
- import {
47
- bufferReviver,
48
- transformJsonParse,
49
- TransformJsonParseOptions,
50
- } from './stream/ndjson/transformJsonParse'
51
- import { transformToNDJson, TransformToNDJsonOptions } from './stream/ndjson/transformToNDJson'
28
+ export * from './stream/ndjson/ndjsonStreamForEach'
29
+ export * from './stream/ndjson/pipelineFromNDJsonFile'
30
+ export * from './stream/ndjson/pipelineToNDJsonFile'
31
+ export * from './stream/ndjson/streamToNDJsonFile'
32
+ export * from './stream/ndjson/transformJsonParse'
33
+ export * from './stream/ndjson/transformToNDJson'
52
34
  export * from './stream/pipeline/pipeline'
53
35
  export * from './stream/readable/readableCreate'
54
36
  export * from './stream/readable/readableForEach'
@@ -56,149 +38,50 @@ export * from './stream/readable/readableFromArray'
56
38
  export * from './stream/readable/readableMap'
57
39
  export * from './stream/readable/readableMapToArray'
58
40
  export * from './stream/readable/readableToArray'
59
- import {
60
- ReadableTyped,
61
- TransformOptions,
62
- TransformTyped,
63
- WritableTyped,
64
- } from './stream/stream.model'
41
+ export * from './stream/stream.model'
65
42
  export * from './stream/transform/transformBuffer'
66
43
  export * from './stream/transform/transformFilter'
67
44
  export * from './stream/transform/transformLimit'
68
45
  export * from './stream/transform/transformLogProgress'
69
- import { transformMap, TransformMapOptions } from './stream/transform/transformMap'
46
+ export * from './stream/transform/transformMap'
70
47
  export * from './stream/transform/transformMapSimple'
71
48
  export * from './stream/transform/transformNoOp'
72
- import { transformMapSync, TransformMapSyncOptions } from './stream/transform/transformMapSync'
49
+ export * from './stream/transform/transformMapSync'
73
50
  export * from './stream/transform/transformSplit'
74
51
  export * from './stream/transform/transformTap'
75
52
  export * from './stream/transform/transformToArray'
76
53
  export * from './stream/transform/transformToString'
77
- import { BaseWorkerClass, WorkerClassInterface } from './stream/transform/worker/baseWorkerClass'
78
- import {
79
- transformMultiThreaded,
80
- TransformMultiThreadedOptions,
81
- } from './stream/transform/worker/transformMultiThreaded'
82
- import { WorkerInput, WorkerOutput } from './stream/transform/worker/transformMultiThreaded.model'
54
+ export * from './stream/transform/worker/baseWorkerClass'
55
+ export * from './stream/transform/worker/transformMultiThreaded'
56
+ export * from './stream/transform/worker/transformMultiThreaded.model'
83
57
  export * from './stream/writable/writableForEach'
84
58
  export * from './stream/writable/writableFork'
85
59
  export * from './stream/writable/writablePushToArray'
86
60
  export * from './stream/writable/writableVoid'
87
- import { inspectAny, InspectAnyOptions, inspectAnyStringifyFn } from './string/inspectAny'
61
+ export * from './string/inspectAny'
88
62
  export * from './util/env.util'
89
63
  export * from './util/lruMemoCache'
90
64
  export * from './util/zip.util'
91
- import { readAjvSchemas, readJsonSchemas } from './validation/ajv/ajv.util'
92
- import { AjvSchema, AjvSchemaCfg, AjvValidationOptions } from './validation/ajv/ajvSchema'
93
- import { AjvValidationError, AjvValidationErrorData } from './validation/ajv/ajvValidationError'
65
+ export * from './validation/ajv/ajv.util'
66
+ export * from './validation/ajv/ajvSchema'
67
+ export * from './validation/ajv/ajvValidationError'
94
68
  export * from './validation/ajv/getAjv'
95
- import { ExtendedJoi, Joi } from './validation/joi/joi.extensions'
96
- import {
97
- AnySchemaTyped,
98
- ArraySchemaTyped,
99
- BooleanSchemaTyped,
100
- NumberSchemaTyped,
101
- ObjectSchemaTyped,
102
- SchemaTyped,
103
- StringSchemaTyped,
104
- } from './validation/joi/joi.model'
69
+ export * from './validation/joi/joi.extensions'
70
+ export * from './validation/joi/joi.model'
105
71
  export * from './validation/joi/joi.shared.schemas'
106
- import { JoiValidationError, JoiValidationErrorData } from './validation/joi/joi.validation.error'
107
- import {
108
- convert,
109
- getValidationResult,
110
- isValid,
111
- JoiValidationResult,
112
- undefinedIfInvalid,
113
- validate,
114
- } from './validation/joi/joi.validation.util'
115
- import { runScript, RunScriptOptions } from './script'
72
+ export * from './validation/joi/joi.validation.error'
73
+ export * from './validation/joi/joi.validation.util'
74
+ export * from './script'
116
75
 
117
76
  export type {
118
77
  GlobbyOptions,
119
78
  FastGlobOptions,
120
- RunScriptOptions,
121
- JoiValidationErrorData,
122
- JoiValidationResult,
123
79
  ValidationErrorItem,
124
- ExtendedJoi,
125
- SchemaTyped,
126
80
  AnySchema,
127
- AnySchemaTyped,
128
- ArraySchemaTyped,
129
- BooleanSchemaTyped,
130
- NumberSchemaTyped,
131
- ObjectSchemaTyped,
132
- StringSchemaTyped,
133
- IDebug,
134
- IDebugger,
135
- SlackServiceCfg,
136
- SlackMessage,
137
- SlackMessageProps,
138
- SlackApiBody,
139
- SlackMessagePrefixHook,
140
- ReadableTyped,
141
- WritableTyped,
142
- TransformTyped,
143
- PipelineFromNDJsonFileOptions,
144
- PipelineToNDJsonFileOptions,
145
- TransformJsonParseOptions,
146
- TransformToNDJsonOptions,
147
- TransformMapOptions,
148
- TransformMapSyncOptions,
149
- NDJSONStreamForEachOptions,
150
- TransformOptions,
151
- TransformMultiThreadedOptions,
152
- WorkerClassInterface,
153
- WorkerInput,
154
- WorkerOutput,
155
- TableDiffOptions,
156
- InspectAnyOptions,
157
81
  Got,
158
- GetGotOptions,
159
82
  AfterResponseHook,
160
83
  BeforeErrorHook,
161
84
  BeforeRequestHook,
162
- AjvValidationOptions,
163
- AjvSchemaCfg,
164
- AjvValidationErrorData,
165
85
  }
166
86
 
167
- export {
168
- globby,
169
- fastGlob,
170
- JoiValidationError,
171
- validate,
172
- getValidationResult,
173
- isValid,
174
- undefinedIfInvalid,
175
- convert,
176
- Joi,
177
- Debug,
178
- SlackService,
179
- slackDefaultMessagePrefixHook,
180
- ndjsonStreamForEach,
181
- pipelineFromNDJsonFile,
182
- pipelineToNDJsonFile,
183
- NDJsonStats,
184
- streamToNDJsonFile,
185
- transformJsonParse,
186
- bufferReviver,
187
- transformToNDJson,
188
- transformMap,
189
- transformMapSync,
190
- transformMultiThreaded,
191
- BaseWorkerClass,
192
- tableDiff,
193
- inspectAny,
194
- inspectAnyStringifyFn,
195
- RequestError,
196
- TimeoutError,
197
- _chunkBuffer,
198
- Ajv,
199
- AjvSchema,
200
- AjvValidationError,
201
- readJsonSchemas,
202
- readAjvSchemas,
203
- runScript,
204
- }
87
+ export { globby, fastGlob, RequestError, TimeoutError, Ajv }
@@ -1,31 +1,45 @@
1
- import { customAlphabet } from 'nanoid'
2
- import { customAlphabet as customAlphabetAsync } from 'nanoid/async'
3
- import { customAlphabet as customAlphabetNonSecure } from 'nanoid/non-secure'
4
-
5
- export const ALPHABET_NUMBER = '0123456789'
6
- export const ALPHABET_LOWERCASE = 'abcdefghijklmnopqrstuvwxyz'
7
- export const ALPHABET_UPPERCASE = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
8
- export const ALPHABET_ALPHANUMERIC_LOWERCASE = [ALPHABET_NUMBER, ALPHABET_LOWERCASE].join('')
9
- export const ALPHABET_ALPHANUMERIC_UPPERCASE = [ALPHABET_NUMBER, ALPHABET_UPPERCASE].join('')
10
- export const ALPHABET_ALPHANUMERIC = [ALPHABET_NUMBER, ALPHABET_LOWERCASE, ALPHABET_UPPERCASE].join(
11
- '',
12
- )
1
+ import * as crypto from 'node:crypto'
2
+ import {
3
+ ALPHABET_ALPHANUMERIC,
4
+ ALPHABET_ALPHANUMERIC_LOWERCASE,
5
+ nanoIdCustomAlphabet,
6
+ } from './nanoid'
13
7
 
14
8
  /**
15
9
  * Generate cryptographically-secure string id.
16
10
  * Powered by `nanoid`.
17
11
  */
18
12
  export function stringId(length = 16, alphabet = ALPHABET_ALPHANUMERIC_LOWERCASE): string {
19
- return customAlphabet(alphabet, length)()
13
+ return nanoIdCustomAlphabet(alphabet, length)()
20
14
  }
21
15
 
22
- export async function stringIdAsync(
23
- length = 16,
24
- alphabet = ALPHABET_ALPHANUMERIC_LOWERCASE,
25
- ): Promise<string> {
26
- return await customAlphabetAsync(alphabet, length)()
16
+ /**
17
+ * Generate a string id of Base62 alphabet (same as "alphanumeric": A-Za-z0-9)
18
+ *
19
+ * Length is 16 (non-configurable currently).
20
+ */
21
+ export const stringIdBase62: () => string = nanoIdCustomAlphabet(ALPHABET_ALPHANUMERIC, 16)
22
+
23
+ /**
24
+ * Generate a string id of Base64 alphabet: A-Za-z0-9+/
25
+ *
26
+ * Default length is 16.
27
+ * Length should be dividable by 4 (otherwise unexpected length will be produced).
28
+ *
29
+ * Dividable by 4 lengths produce ids with no padding `=` characters, which is optimal.
30
+ */
31
+ export function stringIdBase64(size = 16): string {
32
+ return crypto.randomBytes(size * 0.75).toString('base64')
27
33
  }
28
34
 
29
- export function stringIdUnsafe(length = 16, alphabet = ALPHABET_ALPHANUMERIC_LOWERCASE): string {
30
- return customAlphabetNonSecure(alphabet, length)()
35
+ /**
36
+ * Generate a string id of Base64url alphabet: A-Za-z0-9-_
37
+ *
38
+ * Default length is 16.
39
+ * Length should be dividable by 4 (otherwise unexpected length will be produced).
40
+ *
41
+ * Base64url always produces strings without a padding character `=`, by design.
42
+ */
43
+ export function stringIdBase64Url(size = 16): string {
44
+ return crypto.randomBytes(size * 0.75).toString('base64url')
31
45
  }
@@ -0,0 +1,105 @@
1
+ /*
2
+
3
+ This file is "vendored" from Nanoid, all credit is to Nanoid authors:
4
+ https://github.com/ai/nanoid/
5
+
6
+ */
7
+
8
+ /* eslint-disable */
9
+
10
+ import { randomFillSync } from 'node:crypto'
11
+
12
+ type RandomFn = (bytes: number) => Buffer
13
+
14
+ export const ALPHABET_NUMBER = '0123456789'
15
+ export const ALPHABET_LOWERCASE = 'abcdefghijklmnopqrstuvwxyz'
16
+ export const ALPHABET_UPPERCASE = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
17
+ export const ALPHABET_ALPHANUMERIC_LOWERCASE = [ALPHABET_NUMBER, ALPHABET_LOWERCASE].join('')
18
+ export const ALPHABET_ALPHANUMERIC_UPPERCASE = [ALPHABET_NUMBER, ALPHABET_UPPERCASE].join('')
19
+ export const ALPHABET_ALPHANUMERIC = [ALPHABET_NUMBER, ALPHABET_LOWERCASE, ALPHABET_UPPERCASE].join(
20
+ '',
21
+ )
22
+ export const ALPHABET_BASE64 = [ALPHABET_ALPHANUMERIC, '+/'].join('')
23
+ export const ALPHABET_BASE64_URL = [ALPHABET_ALPHANUMERIC, '-_'].join('')
24
+
25
+ // It is best to make fewer, larger requests to the crypto module to
26
+ // avoid system call overhead. So, random numbers are generated in a
27
+ // pool. The pool is a Buffer that is larger than the initial random
28
+ // request size by this multiplier. The pool is enlarged if subsequent
29
+ // requests exceed the maximum buffer size.
30
+ const POOL_SIZE_MULTIPLIER = 128
31
+ let pool: Buffer
32
+ let poolOffset: number
33
+
34
+ function fillPool(bytes: number): void {
35
+ if (!pool || pool.length < bytes) {
36
+ pool = Buffer.allocUnsafe(bytes * POOL_SIZE_MULTIPLIER)
37
+ randomFillSync(pool)
38
+ poolOffset = 0
39
+ } else if (poolOffset + bytes > pool.length) {
40
+ randomFillSync(pool)
41
+ poolOffset = 0
42
+ }
43
+ poolOffset += bytes
44
+ }
45
+
46
+ function random(bytes: number): Buffer {
47
+ // `-=` convert `bytes` to number to prevent `valueOf` abusing
48
+ fillPool((bytes -= 0))
49
+ return pool.subarray(poolOffset - bytes, poolOffset)
50
+ }
51
+
52
+ function customRandom(alphabet: string, defaultSize: number, getRandom: RandomFn) {
53
+ // First, a bitmask is necessary to generate the ID. The bitmask makes bytes
54
+ // values closer to the alphabet size. The bitmask calculates the closest
55
+ // `2^31 - 1` number, which exceeds the alphabet size.
56
+ // For example, the bitmask for the alphabet size 30 is 31 (00011111).
57
+ const mask = (2 << (31 - Math.clz32((alphabet.length - 1) | 1))) - 1
58
+ // Though, the bitmask solution is not perfect since the bytes exceeding
59
+ // the alphabet size are refused. Therefore, to reliably generate the ID,
60
+ // the random bytes redundancy has to be satisfied.
61
+
62
+ // Note: every hardware random generator call is performance expensive,
63
+ // because the system call for entropy collection takes a lot of time.
64
+ // So, to avoid additional system calls, extra bytes are requested in advance.
65
+
66
+ // Next, a step determines how many random bytes to generate.
67
+ // The number of random bytes gets decided upon the ID size, mask,
68
+ // alphabet size, and magic number 1.6 (using 1.6 peaks at performance
69
+ // according to benchmarks).
70
+ const step = Math.ceil((1.6 * mask * defaultSize) / alphabet.length)
71
+
72
+ return (size = defaultSize) => {
73
+ let id = ''
74
+ while (true) {
75
+ const bytes = getRandom(step)
76
+ // A compact alternative for `for (let i = 0; i < step; i++)`.
77
+ let i = step
78
+ while (i--) {
79
+ // Adding `|| ''` refuses a random byte that exceeds the alphabet size.
80
+ id += alphabet[bytes[i]! & mask] || ''
81
+ if (id.length === size) return id
82
+ }
83
+ }
84
+ }
85
+ }
86
+
87
+ export function nanoIdCustomAlphabet(alphabet: string, size = 21): (size?: number) => string {
88
+ return customRandom(alphabet, size, random)
89
+ }
90
+
91
+ export function nanoid(size = 21): string {
92
+ // `-=` convert `size` to number to prevent `valueOf` abusing
93
+ fillPool((size -= 0))
94
+ let id = ''
95
+ // We are reading directly from the random pool to avoid creating new array
96
+ for (let i = poolOffset - size; i < poolOffset; i++) {
97
+ // It is incorrect to use bytes exceeding the alphabet size.
98
+ // The following mask reduces the random byte in the 0-255 value
99
+ // range to the 0-63 value range. Therefore, adding hacks, such
100
+ // as empty string fallback or magic numbers, is unneccessary because
101
+ // the bitmask trims bytes down to the alphabet size.
102
+ id += ALPHABET_BASE64_URL[pool[i]! & 63]
103
+ }
104
+ return id
105
+ }
@@ -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,15 +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
 
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)
63
+
50
64
  /**
51
65
  * `_` should NOT be allowed to be able to use slug-ids as part of natural ids with `_` separator.
52
66
  */
53
- export const SLUG_PATTERN = /^[a-z0-9-]*$/
67
+ export const SLUG_REGEX = /^[a-z0-9-]*$/
54
68
 
55
69
  /**
56
70
  * "Slug" - a valid URL, filename, etc.
57
71
  */
58
- export const slugSchema = stringSchema.regex(/^[a-z0-9-]{1,255}$/)
72
+ export const slugSchema = stringSchema.regex(SLUG_REGEX).min(1).max(255)
59
73
 
60
74
  const TS_2500 = 16725225600 // 2500-01-01
61
75
  const TS_2000 = 946684800 // 2000-01-01
@@ -94,8 +108,8 @@ export const emailSchema = stringSchema.email().lowercase()
94
108
  /**
95
109
  * Pattern is simplified for our use, it's not a canonical SemVer.
96
110
  */
97
- export const SEM_VER_PATTERN = /^[0-9]+\.[0-9]+\.[0-9]+$/
98
- 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)
99
113
  // todo: .error(() => 'should be SemVer')
100
114
 
101
115
  export const userAgentSchema = stringSchema