@naturalcycles/nodejs-lib 13.45.4 → 14.0.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.
Files changed (197) hide show
  1. package/dist/bin/generate-build-info.js +15 -18
  2. package/dist/bin/json2env.js +6 -9
  3. package/dist/bin/kpy.js +6 -9
  4. package/dist/bin/secrets-decrypt.d.ts +1 -1
  5. package/dist/bin/secrets-decrypt.js +9 -12
  6. package/dist/bin/secrets-encrypt.d.ts +1 -1
  7. package/dist/bin/secrets-encrypt.js +9 -12
  8. package/dist/bin/secrets-gen-key.js +8 -11
  9. package/dist/bin/slack-this.js +6 -9
  10. package/dist/buffer/buffer.util.js +1 -4
  11. package/dist/colors/colors.d.ts +26 -27
  12. package/dist/colors/colors.js +29 -33
  13. package/dist/csv/csvReader.js +4 -8
  14. package/dist/csv/csvWriter.js +6 -12
  15. package/dist/csv/transformToCSV.d.ts +2 -2
  16. package/dist/csv/transformToCSV.js +5 -8
  17. package/dist/diff/tableDiff.js +4 -7
  18. package/dist/fs/fs2.d.ts +1 -1
  19. package/dist/fs/fs2.js +82 -86
  20. package/dist/fs/json2env.js +18 -28
  21. package/dist/fs/kpy.js +28 -33
  22. package/dist/index.d.ts +71 -71
  23. package/dist/index.js +73 -78
  24. package/dist/infra/process.util.js +22 -28
  25. package/dist/jwt/jwt.service.js +16 -21
  26. package/dist/log/log.util.js +4 -7
  27. package/dist/script/runScript.js +11 -15
  28. package/dist/secret/secrets-decrypt.util.js +18 -22
  29. package/dist/secret/secrets-encrypt.util.js +17 -21
  30. package/dist/security/crypto.util.js +24 -34
  31. package/dist/security/hash.util.js +19 -37
  32. package/dist/security/id.util.js +11 -18
  33. package/dist/security/nanoid.js +15 -20
  34. package/dist/security/secret.util.js +20 -30
  35. package/dist/slack/slack.service.d.ts +1 -1
  36. package/dist/slack/slack.service.js +11 -16
  37. package/dist/slack/slack.service.model.d.ts +1 -1
  38. package/dist/slack/slack.service.model.js +1 -2
  39. package/dist/stream/ndjson/ndjson.model.js +7 -11
  40. package/dist/stream/ndjson/ndjsonMap.d.ts +1 -1
  41. package/dist/stream/ndjson/ndjsonMap.js +11 -14
  42. package/dist/stream/ndjson/ndjsonStreamForEach.d.ts +1 -1
  43. package/dist/stream/ndjson/ndjsonStreamForEach.js +9 -12
  44. package/dist/stream/ndjson/transformJsonParse.d.ts +1 -1
  45. package/dist/stream/ndjson/transformJsonParse.js +4 -9
  46. package/dist/stream/ndjson/transformToNDJson.d.ts +1 -1
  47. package/dist/stream/ndjson/transformToNDJson.js +5 -8
  48. package/dist/stream/pipeline/pipeline.js +11 -17
  49. package/dist/stream/progressLogger.d.ts +1 -1
  50. package/dist/stream/progressLogger.js +22 -28
  51. package/dist/stream/readable/readableCreate.d.ts +1 -1
  52. package/dist/stream/readable/readableCreate.js +5 -9
  53. package/dist/stream/readable/readableForEach.d.ts +2 -2
  54. package/dist/stream/readable/readableForEach.js +7 -11
  55. package/dist/stream/readable/readableFromArray.d.ts +1 -1
  56. package/dist/stream/readable/readableFromArray.js +4 -7
  57. package/dist/stream/readable/readableToArray.d.ts +1 -1
  58. package/dist/stream/readable/readableToArray.js +1 -4
  59. package/dist/stream/sizeStack.js +7 -11
  60. package/dist/stream/stream.model.js +1 -2
  61. package/dist/stream/stream.util.js +1 -4
  62. package/dist/stream/transform/transformChunk.d.ts +1 -1
  63. package/dist/stream/transform/transformChunk.js +3 -6
  64. package/dist/stream/transform/transformFilter.d.ts +2 -2
  65. package/dist/stream/transform/transformFilter.js +6 -10
  66. package/dist/stream/transform/transformLimit.d.ts +2 -2
  67. package/dist/stream/transform/transformLimit.js +6 -11
  68. package/dist/stream/transform/transformLogProgress.d.ts +2 -2
  69. package/dist/stream/transform/transformLogProgress.js +5 -8
  70. package/dist/stream/transform/transformMap.d.ts +1 -1
  71. package/dist/stream/transform/transformMap.js +18 -22
  72. package/dist/stream/transform/transformMapSimple.d.ts +1 -1
  73. package/dist/stream/transform/transformMapSimple.js +6 -9
  74. package/dist/stream/transform/transformMapSync.d.ts +3 -3
  75. package/dist/stream/transform/transformMapSync.js +14 -19
  76. package/dist/stream/transform/transformNoOp.d.ts +1 -1
  77. package/dist/stream/transform/transformNoOp.js +3 -6
  78. package/dist/stream/transform/transformOffset.d.ts +1 -1
  79. package/dist/stream/transform/transformOffset.js +5 -8
  80. package/dist/stream/transform/transformSplit.d.ts +1 -1
  81. package/dist/stream/transform/transformSplit.js +5 -9
  82. package/dist/stream/transform/transformTap.d.ts +1 -1
  83. package/dist/stream/transform/transformTap.js +3 -6
  84. package/dist/stream/transform/transformTee.d.ts +1 -1
  85. package/dist/stream/transform/transformTee.js +7 -10
  86. package/dist/stream/transform/transformThrottle.d.ts +1 -1
  87. package/dist/stream/transform/transformThrottle.js +9 -12
  88. package/dist/stream/transform/transformToArray.d.ts +1 -1
  89. package/dist/stream/transform/transformToArray.js +3 -6
  90. package/dist/stream/transform/worker/baseWorkerClass.d.ts +1 -1
  91. package/dist/stream/transform/worker/baseWorkerClass.js +1 -5
  92. package/dist/stream/transform/worker/transformMultiThreaded.d.ts +1 -1
  93. package/dist/stream/transform/worker/transformMultiThreaded.js +12 -11
  94. package/dist/stream/transform/worker/transformMultiThreaded.model.js +1 -2
  95. package/dist/stream/transform/worker/workerClassProxy.js +6 -4
  96. package/dist/stream/writable/writableForEach.d.ts +2 -2
  97. package/dist/stream/writable/writableForEach.js +6 -10
  98. package/dist/stream/writable/writableFork.d.ts +1 -1
  99. package/dist/stream/writable/writableFork.js +6 -9
  100. package/dist/stream/writable/writableLimit.d.ts +1 -1
  101. package/dist/stream/writable/writableLimit.js +3 -6
  102. package/dist/stream/writable/writablePushToArray.d.ts +1 -1
  103. package/dist/stream/writable/writablePushToArray.js +3 -6
  104. package/dist/stream/writable/writableVoid.d.ts +1 -1
  105. package/dist/stream/writable/writableVoid.js +3 -6
  106. package/dist/string/inspect.js +8 -13
  107. package/dist/util/buildInfo.util.js +12 -15
  108. package/dist/util/env.util.js +5 -9
  109. package/dist/util/exec2.js +17 -21
  110. package/dist/util/git2.js +17 -20
  111. package/dist/util/lruMemoCache.js +3 -7
  112. package/dist/util/zip.util.js +14 -25
  113. package/dist/validation/ajv/ajv.util.d.ts +3 -3
  114. package/dist/validation/ajv/ajv.util.js +6 -10
  115. package/dist/validation/ajv/ajvSchema.d.ts +2 -2
  116. package/dist/validation/ajv/ajvSchema.js +14 -18
  117. package/dist/validation/ajv/ajvValidationError.js +2 -6
  118. package/dist/validation/ajv/getAjv.d.ts +1 -1
  119. package/dist/validation/ajv/getAjv.js +9 -9
  120. package/dist/validation/joi/joi.extensions.d.ts +2 -2
  121. package/dist/validation/joi/joi.extensions.js +6 -10
  122. package/dist/validation/joi/joi.model.js +1 -2
  123. package/dist/validation/joi/joi.shared.schemas.d.ts +2 -2
  124. package/dist/validation/joi/joi.shared.schemas.js +61 -74
  125. package/dist/validation/joi/joi.validation.error.js +2 -6
  126. package/dist/validation/joi/joi.validation.util.d.ts +1 -1
  127. package/dist/validation/joi/joi.validation.util.js +10 -17
  128. package/dist/validation/joi/number.extensions.js +1 -4
  129. package/dist/validation/joi/string.extensions.js +4 -7
  130. package/dist/yargs.util.js +5 -8
  131. package/package.json +5 -4
  132. package/src/bin/generate-build-info.ts +3 -3
  133. package/src/bin/json2env.ts +2 -2
  134. package/src/bin/kpy.ts +2 -2
  135. package/src/bin/secrets-decrypt.ts +7 -8
  136. package/src/bin/secrets-encrypt.ts +7 -8
  137. package/src/bin/secrets-gen-key.ts +2 -2
  138. package/src/bin/slack-this.ts +2 -2
  139. package/src/csv/transformToCSV.ts +3 -3
  140. package/src/fs/fs2.ts +4 -4
  141. package/src/fs/json2env.ts +2 -2
  142. package/src/fs/kpy.ts +2 -2
  143. package/src/index.ts +71 -71
  144. package/src/jwt/jwt.service.ts +2 -2
  145. package/src/log/log.util.ts +1 -1
  146. package/src/script/runScript.ts +4 -3
  147. package/src/secret/secrets-decrypt.util.ts +3 -3
  148. package/src/secret/secrets-encrypt.util.ts +3 -3
  149. package/src/security/crypto.util.ts +1 -1
  150. package/src/security/id.util.ts +1 -1
  151. package/src/security/secret.util.ts +2 -2
  152. package/src/slack/slack.service.model.ts +1 -1
  153. package/src/slack/slack.service.ts +3 -3
  154. package/src/stream/ndjson/ndjson.model.ts +1 -1
  155. package/src/stream/ndjson/ndjsonMap.ts +2 -2
  156. package/src/stream/ndjson/ndjsonStreamForEach.ts +2 -2
  157. package/src/stream/ndjson/transformJsonParse.ts +1 -1
  158. package/src/stream/ndjson/transformToNDJson.ts +1 -1
  159. package/src/stream/pipeline/pipeline.ts +1 -1
  160. package/src/stream/progressLogger.ts +3 -3
  161. package/src/stream/readable/readableCreate.ts +1 -1
  162. package/src/stream/readable/readableForEach.ts +4 -4
  163. package/src/stream/readable/readableFromArray.ts +1 -1
  164. package/src/stream/readable/readableToArray.ts +1 -1
  165. package/src/stream/sizeStack.ts +2 -2
  166. package/src/stream/transform/transformChunk.ts +1 -1
  167. package/src/stream/transform/transformFilter.ts +3 -3
  168. package/src/stream/transform/transformLimit.ts +3 -3
  169. package/src/stream/transform/transformLogProgress.ts +3 -3
  170. package/src/stream/transform/transformMap.ts +5 -5
  171. package/src/stream/transform/transformMapSimple.ts +1 -1
  172. package/src/stream/transform/transformMapSync.ts +5 -5
  173. package/src/stream/transform/transformNoOp.ts +1 -1
  174. package/src/stream/transform/transformOffset.ts +2 -2
  175. package/src/stream/transform/transformSplit.ts +1 -1
  176. package/src/stream/transform/transformTap.ts +1 -1
  177. package/src/stream/transform/transformTee.ts +3 -3
  178. package/src/stream/transform/transformThrottle.ts +1 -1
  179. package/src/stream/transform/transformToArray.ts +1 -1
  180. package/src/stream/transform/worker/baseWorkerClass.ts +1 -1
  181. package/src/stream/transform/worker/transformMultiThreaded.ts +8 -3
  182. package/src/stream/transform/worker/workerClassProxy.js +6 -4
  183. package/src/stream/writable/writableForEach.ts +3 -3
  184. package/src/stream/writable/writableFork.ts +3 -3
  185. package/src/stream/writable/writableLimit.ts +1 -1
  186. package/src/stream/writable/writablePushToArray.ts +1 -1
  187. package/src/stream/writable/writableVoid.ts +1 -1
  188. package/src/util/buildInfo.util.ts +2 -2
  189. package/src/util/exec2.ts +1 -1
  190. package/src/util/git2.ts +2 -2
  191. package/src/validation/ajv/ajv.util.ts +4 -4
  192. package/src/validation/ajv/ajvSchema.ts +4 -5
  193. package/src/validation/ajv/getAjv.ts +7 -3
  194. package/src/validation/joi/joi.extensions.ts +4 -4
  195. package/src/validation/joi/joi.shared.schemas.ts +3 -3
  196. package/src/validation/joi/joi.validation.util.ts +2 -2
  197. package/src/yargs.util.ts +1 -0
@@ -1,58 +1,47 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.deflateBuffer = deflateBuffer;
4
- exports.inflateBuffer = inflateBuffer;
5
- exports.deflateString = deflateString;
6
- exports.inflateToString = inflateToString;
7
- exports.gzipBuffer = gzipBuffer;
8
- exports.gunzipBuffer = gunzipBuffer;
9
- exports.gzipString = gzipString;
10
- exports.gunzipToString = gunzipToString;
11
- const tslib_1 = require("tslib");
12
- const node_util_1 = require("node:util");
13
- const node_zlib_1 = tslib_1.__importDefault(require("node:zlib"));
14
- const deflate = (0, node_util_1.promisify)(node_zlib_1.default.deflate.bind(node_zlib_1.default));
15
- const inflate = (0, node_util_1.promisify)(node_zlib_1.default.inflate.bind(node_zlib_1.default));
16
- const gzip = (0, node_util_1.promisify)(node_zlib_1.default.gzip.bind(node_zlib_1.default));
17
- const gunzip = (0, node_util_1.promisify)(node_zlib_1.default.gunzip.bind(node_zlib_1.default));
1
+ import { promisify } from 'node:util';
2
+ import zlib from 'node:zlib';
3
+ const deflate = promisify(zlib.deflate.bind(zlib));
4
+ const inflate = promisify(zlib.inflate.bind(zlib));
5
+ const gzip = promisify(zlib.gzip.bind(zlib));
6
+ const gunzip = promisify(zlib.gunzip.bind(zlib));
18
7
  // string > compressed buffer
19
8
  /**
20
9
  * deflateBuffer uses `deflate`.
21
10
  * It's 9 bytes shorter than `gzip`.
22
11
  */
23
- async function deflateBuffer(buf, options = {}) {
12
+ export async function deflateBuffer(buf, options = {}) {
24
13
  return await deflate(buf, options);
25
14
  }
26
- async function inflateBuffer(buf, options = {}) {
15
+ export async function inflateBuffer(buf, options = {}) {
27
16
  return await inflate(buf, options);
28
17
  }
29
18
  /**
30
19
  * deflateString uses `deflate`.
31
20
  * It's 9 bytes shorter than `gzip`.
32
21
  */
33
- async function deflateString(s, options) {
22
+ export async function deflateString(s, options) {
34
23
  return await deflateBuffer(Buffer.from(s), options);
35
24
  }
36
- async function inflateToString(buf, options) {
25
+ export async function inflateToString(buf, options) {
37
26
  return (await inflateBuffer(buf, options)).toString();
38
27
  }
39
28
  /**
40
29
  * gzipBuffer uses `gzip`
41
30
  * It's 9 bytes longer than `deflate`.
42
31
  */
43
- async function gzipBuffer(buf, options = {}) {
32
+ export async function gzipBuffer(buf, options = {}) {
44
33
  return await gzip(buf, options);
45
34
  }
46
- async function gunzipBuffer(buf, options = {}) {
35
+ export async function gunzipBuffer(buf, options = {}) {
47
36
  return await gunzip(buf, options);
48
37
  }
49
38
  /**
50
39
  * gzipString uses `gzip`.
51
40
  * It's 9 bytes longer than `deflate`.
52
41
  */
53
- async function gzipString(s, options) {
42
+ export async function gzipString(s, options) {
54
43
  return await gzipBuffer(Buffer.from(s), options);
55
44
  }
56
- async function gunzipToString(buf, options) {
45
+ export async function gunzipToString(buf, options) {
57
46
  return (await gunzipBuffer(buf, options)).toString();
58
47
  }
@@ -1,7 +1,7 @@
1
1
  import type { JsonSchema } from '@naturalcycles/js-lib';
2
- import type { FastGlobOptions } from '../..';
3
- import type { AjvSchemaCfg } from './ajvSchema';
4
- import { AjvSchema } from './ajvSchema';
2
+ import type { FastGlobOptions } from '../../index.js';
3
+ import type { AjvSchemaCfg } from './ajvSchema.js';
4
+ import { AjvSchema } from './ajvSchema.js';
5
5
  /**
6
6
  * Does fs.readFileSync + JSON.parse for ALL files matching the passed `glob` pattern.
7
7
  * E.g `someDir/**\/*.schema.json`
@@ -1,9 +1,5 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.readJsonSchemas = readJsonSchemas;
4
- exports.readAjvSchemas = readAjvSchemas;
5
- const __1 = require("../..");
6
- const ajvSchema_1 = require("./ajvSchema");
1
+ import { fastGlob, fs2 } from '../../index.js';
2
+ import { AjvSchema } from './ajvSchema.js';
7
3
  /**
8
4
  * Does fs.readFileSync + JSON.parse for ALL files matching the passed `glob` pattern.
9
5
  * E.g `someDir/**\/*.schema.json`
@@ -12,8 +8,8 @@ const ajvSchema_1 = require("./ajvSchema");
12
8
  *
13
9
  * @experimental
14
10
  */
15
- function readJsonSchemas(patterns, opt) {
16
- return __1.fastGlob.sync(patterns, opt).map(fileName => __1.fs2.readJson(fileName));
11
+ export function readJsonSchemas(patterns, opt) {
12
+ return fastGlob.sync(patterns, opt).map(fileName => fs2.readJson(fileName));
17
13
  }
18
14
  /**
19
15
  * Reads json schemas from given dir (glob pattern).
@@ -22,9 +18,9 @@ function readJsonSchemas(patterns, opt) {
22
18
  *
23
19
  * @experimental
24
20
  */
25
- function readAjvSchemas(patterns, cfg) {
21
+ export function readAjvSchemas(patterns, cfg) {
26
22
  const schemas = readJsonSchemas(patterns);
27
- return schemas.map(schema => ajvSchema_1.AjvSchema.create(schema, {
23
+ return schemas.map(schema => AjvSchema.create(schema, {
28
24
  schemas,
29
25
  ...cfg,
30
26
  }));
@@ -1,6 +1,6 @@
1
1
  import type { CommonLogger, JsonSchema, JsonSchemaBuilder } from '@naturalcycles/js-lib';
2
- import type Ajv from 'ajv';
3
- import { AjvValidationError } from './ajvValidationError';
2
+ import type { Ajv } from 'ajv';
3
+ import { AjvValidationError } from './ajvValidationError.js';
4
4
  export interface AjvValidationOptions {
5
5
  objectName?: string;
6
6
  objectId?: string;
@@ -1,17 +1,14 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.AjvSchema = void 0;
4
- const js_lib_1 = require("@naturalcycles/js-lib");
5
- const index_1 = require("../../index");
6
- const ajvValidationError_1 = require("./ajvValidationError");
7
- const getAjv_1 = require("./getAjv");
1
+ import { _filterNullishValues, _isObject, _substringBefore, JsonSchemaAnyBuilder, } from '@naturalcycles/js-lib';
2
+ import { _inspect, fs2, requireFileToExist } from '../../index.js';
3
+ import { AjvValidationError } from './ajvValidationError.js';
4
+ import { getAjv } from './getAjv.js';
8
5
  /**
9
6
  * On creation - compiles ajv validation function.
10
7
  * Provides convenient methods, error reporting, etc.
11
8
  *
12
9
  * @experimental
13
10
  */
14
- class AjvSchema {
11
+ export class AjvSchema {
15
12
  schema;
16
13
  constructor(schema, cfg = {}) {
17
14
  this.schema = schema;
@@ -21,11 +18,11 @@ class AjvSchema {
21
18
  separator: '\n',
22
19
  ...cfg,
23
20
  ajv: cfg.ajv ||
24
- (0, getAjv_1.getAjv)({
21
+ getAjv({
25
22
  schemas: cfg.schemas?.map(s => {
26
23
  if (s instanceof AjvSchema)
27
24
  return s.schema;
28
- if (s instanceof js_lib_1.JsonSchemaAnyBuilder)
25
+ if (s instanceof JsonSchemaAnyBuilder)
29
26
  return s.build();
30
27
  return s;
31
28
  }),
@@ -33,7 +30,7 @@ class AjvSchema {
33
30
  // verbose: true,
34
31
  }),
35
32
  // Auto-detecting "ObjectName" from $id of the schema (e.g "Address.schema.json")
36
- objectName: cfg.objectName || (schema.$id ? (0, js_lib_1._substringBefore)(schema.$id, '.') : undefined),
33
+ objectName: cfg.objectName || (schema.$id ? _substringBefore(schema.$id, '.') : undefined),
37
34
  };
38
35
  this.validateFunction = this.cfg.ajv.compile(schema);
39
36
  }
@@ -49,7 +46,7 @@ class AjvSchema {
49
46
  static create(schema, cfg = {}) {
50
47
  if (schema instanceof AjvSchema)
51
48
  return schema;
52
- if (schema instanceof js_lib_1.JsonSchemaAnyBuilder) {
49
+ if (schema instanceof JsonSchemaAnyBuilder) {
53
50
  return new AjvSchema(schema.build(), cfg);
54
51
  }
55
52
  return new AjvSchema(schema, cfg);
@@ -59,8 +56,8 @@ class AjvSchema {
59
56
  * Convenient method that just does fs.readFileSync for you.
60
57
  */
61
58
  static readJsonSync(filePath, cfg = {}) {
62
- (0, index_1.requireFileToExist)(filePath);
63
- const schema = index_1.fs2.readJson(filePath);
59
+ requireFileToExist(filePath);
60
+ const schema = fs2.readJson(filePath);
64
61
  return new AjvSchema(schema, cfg);
65
62
  }
66
63
  cfg;
@@ -83,18 +80,18 @@ class AjvSchema {
83
80
  if (this.isValid(obj))
84
81
  return;
85
82
  const errors = this.validateFunction.errors;
86
- const { objectId = (0, js_lib_1._isObject)(obj) ? obj['id'] : undefined, objectName = this.cfg.objectName, logErrors = this.cfg.logErrors, separator = this.cfg.separator, } = opt;
83
+ const { objectId = _isObject(obj) ? obj['id'] : undefined, objectName = this.cfg.objectName, logErrors = this.cfg.logErrors, separator = this.cfg.separator, } = opt;
87
84
  const name = [objectName || 'Object', objectId].filter(Boolean).join('.');
88
85
  let message = this.cfg.ajv.errorsText(errors, {
89
86
  dataVar: name,
90
87
  separator,
91
88
  });
92
- const strValue = (0, index_1._inspect)(obj, { maxLen: 1000 });
89
+ const strValue = _inspect(obj, { maxLen: 1000 });
93
90
  message = [message, 'Input: ' + strValue].join(separator);
94
91
  if (logErrors) {
95
92
  this.cfg.logger.error(errors);
96
93
  }
97
- return new ajvValidationError_1.AjvValidationError(message, (0, js_lib_1._filterNullishValues)({
94
+ return new AjvValidationError(message, _filterNullishValues({
98
95
  errors,
99
96
  userFriendly: true,
100
97
  objectName,
@@ -105,4 +102,3 @@ class AjvSchema {
105
102
  return this.validateFunction(obj);
106
103
  }
107
104
  }
108
- exports.AjvSchema = AjvSchema;
@@ -1,12 +1,8 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.AjvValidationError = void 0;
4
- const js_lib_1 = require("@naturalcycles/js-lib");
5
- class AjvValidationError extends js_lib_1.AppError {
1
+ import { AppError } from '@naturalcycles/js-lib';
2
+ export class AjvValidationError extends AppError {
6
3
  constructor(message, data) {
7
4
  super(message, data, {
8
5
  name: 'AjvValidationError',
9
6
  });
10
7
  }
11
8
  }
12
- exports.AjvValidationError = AjvValidationError;
@@ -1,5 +1,5 @@
1
1
  import type { Options } from 'ajv';
2
- import Ajv from 'ajv';
2
+ import { Ajv } from 'ajv';
3
3
  /**
4
4
  * Create Ajv with modified defaults.
5
5
  *
@@ -1,8 +1,6 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getAjv = getAjv;
4
- const tslib_1 = require("tslib");
5
- const ajv_1 = tslib_1.__importDefault(require("ajv"));
1
+ import { Ajv } from 'ajv';
2
+ import ajvFormats from 'ajv-formats';
3
+ import ajvKeywords from 'ajv-keywords';
6
4
  const AJV_OPTIONS = {
7
5
  removeAdditional: true,
8
6
  allErrors: true,
@@ -17,8 +15,8 @@ const AJV_OPTIONS = {
17
15
  *
18
16
  * https://ajv.js.org/options.html
19
17
  */
20
- function getAjv(opt) {
21
- const ajv = new ajv_1.default({
18
+ export function getAjv(opt) {
19
+ const ajv = new Ajv({
22
20
  ...AJV_OPTIONS,
23
21
  ...opt,
24
22
  });
@@ -26,9 +24,11 @@ function getAjv(opt) {
26
24
  addCustomAjvFormats(ajv);
27
25
  // Adds ajv "formats"
28
26
  // https://ajv.js.org/guide/formats.html
29
- require('ajv-formats')(ajv);
27
+ // @ts-expect-error types are wrong
28
+ ajvFormats(ajv);
30
29
  // https://ajv.js.org/packages/ajv-keywords.html
31
- require('ajv-keywords')(ajv, [
30
+ // @ts-expect-error types are wrong
31
+ ajvKeywords(ajv, [
32
32
  'transform', // trim, toLowerCase, etc.
33
33
  'uniqueItemProperties',
34
34
  'instanceof',
@@ -1,6 +1,6 @@
1
1
  import JoiLib from 'joi';
2
- import type { NumberSchema } from './number.extensions';
3
- import type { StringSchema } from './string.extensions';
2
+ import type { NumberSchema } from './number.extensions.js';
3
+ import type { StringSchema } from './string.extensions.js';
4
4
  export interface ExtendedJoi extends JoiLib.Root {
5
5
  string: <TSchema = string>() => StringSchema<TSchema>;
6
6
  number: <TSchema = number>() => NumberSchema<TSchema>;
@@ -1,15 +1,11 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Joi = void 0;
4
- const tslib_1 = require("tslib");
5
- const joi_1 = tslib_1.__importDefault(require("joi"));
6
- const number_extensions_1 = require("./number.extensions");
7
- const string_extensions_1 = require("./string.extensions");
1
+ import JoiLib from 'joi';
2
+ import { numberExtensions } from './number.extensions.js';
3
+ import { stringExtensions } from './string.extensions.js';
8
4
  /**
9
5
  * This is the only right place to import Joi from
10
6
  */
11
7
  // eslint-disable-next-line @typescript-eslint/naming-convention
12
- exports.Joi = joi_1.default.defaults(schema => {
8
+ export const Joi = JoiLib.defaults(schema => {
13
9
  // hack to prevent infinite recursion due to .empty('') where '' is a stringSchema itself
14
10
  if (schema.type === 'string') {
15
11
  return (schema
@@ -25,5 +21,5 @@ exports.Joi = joi_1.default.defaults(schema => {
25
21
  // return schema.empty(null)
26
22
  return schema;
27
23
  })
28
- .extend((joi) => (0, string_extensions_1.stringExtensions)(joi))
29
- .extend((joi) => (0, number_extensions_1.numberExtensions)(joi));
24
+ .extend((joi) => stringExtensions(joi))
25
+ .extend((joi) => numberExtensions(joi));
@@ -1,6 +1,5 @@
1
- "use strict";
2
1
  // export interface ObjectSchema<T = any> extends JoiObjectSchema<T> {
3
2
  // // Open-ended index signature to allow for easier .concat(baseDBEntitySchema)
4
3
  // [k: string]: any
5
4
  // }
6
- Object.defineProperty(exports, "__esModule", { value: true });
5
+ export {};
@@ -1,7 +1,7 @@
1
1
  import type { BaseDBEntity, IANATimezone, IsoDateTime, NumberEnum, StringEnum, UnixTimestamp, UnixTimestampMillis } from '@naturalcycles/js-lib';
2
2
  import type { AlternativesSchema, AnySchema, ArraySchema, ObjectSchema } from 'joi';
3
- import type { NumberSchema } from './number.extensions';
4
- import type { StringSchema } from './string.extensions';
3
+ import type { NumberSchema } from './number.extensions.js';
4
+ import type { StringSchema } from './string.extensions.js';
5
5
  export declare const booleanSchema: import("joi").BooleanSchema<boolean>;
6
6
  export declare const booleanDefaultToFalseSchema: import("joi").BooleanSchema<boolean>;
7
7
  export declare const stringSchema: StringSchema<string>;
@@ -1,150 +1,137 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.uuidSchema = exports.macAddressSchema = exports.baseDBEntitySchema = exports.ipAddressSchema = exports.ianaTimezoneSchema = 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.urlSchema = exports.numberEnumKeySchema = exports.numberEnumValueSchema = exports.stringEnumKeySchema = exports.stringEnumValueSchema = exports.dateTimeStringSchema = exports.DATE_TIME_STRING_REGEX = exports.dateIntervalStringSchema = exports.dateObjectSchema = exports.binarySchema = exports.dateStringSchema = exports.percentageSchema = exports.integerSchema = exports.numberSchemaTyped = exports.numberSchema = exports.stringSchemaTyped = exports.stringSchema = exports.booleanDefaultToFalseSchema = exports.booleanSchema = void 0;
4
- exports.arraySchema = arraySchema;
5
- exports.objectSchema = objectSchema;
6
- exports.oneOfSchema = oneOfSchema;
7
- const js_lib_1 = require("@naturalcycles/js-lib");
8
- const joi_extensions_1 = require("./joi.extensions");
9
- exports.booleanSchema = joi_extensions_1.Joi.boolean();
10
- exports.booleanDefaultToFalseSchema = joi_extensions_1.Joi.boolean().default(false);
11
- exports.stringSchema = joi_extensions_1.Joi.string();
12
- const stringSchemaTyped = () => joi_extensions_1.Joi.string();
13
- exports.stringSchemaTyped = stringSchemaTyped;
14
- exports.numberSchema = joi_extensions_1.Joi.number();
15
- const numberSchemaTyped = () => joi_extensions_1.Joi.number();
16
- exports.numberSchemaTyped = numberSchemaTyped;
17
- exports.integerSchema = joi_extensions_1.Joi.number().integer();
18
- exports.percentageSchema = joi_extensions_1.Joi.number().integer().min(0).max(100);
19
- exports.dateStringSchema = exports.stringSchema.dateString();
20
- exports.binarySchema = joi_extensions_1.Joi.binary();
21
- exports.dateObjectSchema = joi_extensions_1.Joi.object().instance(Date);
1
+ import { _numberEnumKeys, _numberEnumValues, _stringEnumKeys, _stringEnumValues, } from '@naturalcycles/js-lib';
2
+ import { Joi } from './joi.extensions.js';
3
+ export const booleanSchema = Joi.boolean();
4
+ export const booleanDefaultToFalseSchema = Joi.boolean().default(false);
5
+ export const stringSchema = Joi.string();
6
+ export const stringSchemaTyped = () => Joi.string();
7
+ export const numberSchema = Joi.number();
8
+ export const numberSchemaTyped = () => Joi.number();
9
+ export const integerSchema = Joi.number().integer();
10
+ export const percentageSchema = Joi.number().integer().min(0).max(100);
11
+ export const dateStringSchema = stringSchema.dateString();
12
+ export const binarySchema = Joi.binary();
13
+ export const dateObjectSchema = Joi.object().instance(Date);
22
14
  const DATE_INTERVAL_REGEX = /^\d{4}-\d{2}-\d{2}\/\d{4}-\d{2}-\d{2}$/;
23
- exports.dateIntervalStringSchema = exports.stringSchema.regex(DATE_INTERVAL_REGEX).messages({
15
+ export const dateIntervalStringSchema = stringSchema.regex(DATE_INTERVAL_REGEX).messages({
24
16
  'string.pattern.base': `must be a DateInterval string`,
25
17
  });
26
- exports.DATE_TIME_STRING_REGEX = /^\d{4}-\d{2}-\d{2}(?:T\d{2}:\d{2}:\d{2}(?:\.\d{1,3})?(?:Z|[+-]\d{2}:\d{2})?)?$/;
27
- exports.dateTimeStringSchema = exports.stringSchema.regex(exports.DATE_TIME_STRING_REGEX).messages({
18
+ export const DATE_TIME_STRING_REGEX = /^\d{4}-\d{2}-\d{2}(?:T\d{2}:\d{2}:\d{2}(?:\.\d{1,3})?(?:Z|[+-]\d{2}:\d{2})?)?$/;
19
+ export const dateTimeStringSchema = stringSchema.regex(DATE_TIME_STRING_REGEX).messages({
28
20
  'string.pattern.base': `must be a DateTime string`,
29
21
  });
30
22
  /**
31
23
  * Allows all values of a String Enum.
32
24
  */
33
- const stringEnumValueSchema = (en) => joi_extensions_1.Joi.string().valid(...(0, js_lib_1._stringEnumValues)(en));
34
- exports.stringEnumValueSchema = stringEnumValueSchema;
25
+ export const stringEnumValueSchema = (en) => Joi.string().valid(..._stringEnumValues(en));
35
26
  /**
36
27
  * Allows all keys of a String Enum.
37
28
  */
38
- const stringEnumKeySchema = (en) => joi_extensions_1.Joi.string().valid(...(0, js_lib_1._stringEnumKeys)(en));
39
- exports.stringEnumKeySchema = stringEnumKeySchema;
29
+ export const stringEnumKeySchema = (en) => Joi.string().valid(..._stringEnumKeys(en));
40
30
  /**
41
31
  * Allows all values of a String Enum.
42
32
  */
43
- const numberEnumValueSchema = (en) => joi_extensions_1.Joi.number().valid(...(0, js_lib_1._numberEnumValues)(en));
44
- exports.numberEnumValueSchema = numberEnumValueSchema;
33
+ export const numberEnumValueSchema = (en) => Joi.number().valid(..._numberEnumValues(en));
45
34
  /**
46
35
  * Allows all keys of a Number Enum.
47
36
  */
48
- const numberEnumKeySchema = (en) => joi_extensions_1.Joi.string().valid(...(0, js_lib_1._numberEnumKeys)(en));
49
- exports.numberEnumKeySchema = numberEnumKeySchema;
50
- const urlSchema = (scheme = 'https') => joi_extensions_1.Joi.string().uri({ scheme });
51
- exports.urlSchema = urlSchema;
52
- function arraySchema(items) {
53
- return items ? joi_extensions_1.Joi.array().items(items) : joi_extensions_1.Joi.array();
37
+ export const numberEnumKeySchema = (en) => Joi.string().valid(..._numberEnumKeys(en));
38
+ export const urlSchema = (scheme = 'https') => Joi.string().uri({ scheme });
39
+ export function arraySchema(items) {
40
+ return items ? Joi.array().items(items) : Joi.array();
54
41
  }
55
- function objectSchema(schema) {
56
- return joi_extensions_1.Joi.object(schema);
42
+ export function objectSchema(schema) {
43
+ return Joi.object(schema);
57
44
  }
58
- function oneOfSchema(...schemas) {
59
- return joi_extensions_1.Joi.alternatives(schemas);
45
+ export function oneOfSchema(...schemas) {
46
+ return Joi.alternatives(schemas);
60
47
  }
61
- exports.anySchema = joi_extensions_1.Joi.any();
62
- exports.anyObjectSchema = joi_extensions_1.Joi.object().options({ stripUnknown: false });
63
- exports.BASE62_REGEX = /^[a-zA-Z0-9]+$/;
64
- exports.BASE64_REGEX = /^[a-zA-Z0-9+/]+={0,2}$/;
65
- exports.BASE64URL_REGEX = /^[a-zA-Z0-9_-]+$/;
66
- exports.base62Schema = exports.stringSchema.regex(exports.BASE62_REGEX);
67
- exports.base64Schema = exports.stringSchema.regex(exports.BASE64_REGEX);
68
- exports.base64UrlSchema = exports.stringSchema.regex(exports.BASE64URL_REGEX);
69
- exports.JWT_REGEX = /^[\w-]+\.[\w-]+\.[\w-]+$/;
70
- exports.jwtSchema = exports.stringSchema.regex(exports.JWT_REGEX);
48
+ export const anySchema = Joi.any();
49
+ export const anyObjectSchema = Joi.object().options({ stripUnknown: false });
50
+ export const BASE62_REGEX = /^[a-zA-Z0-9]+$/;
51
+ export const BASE64_REGEX = /^[a-zA-Z0-9+/]+={0,2}$/;
52
+ export const BASE64URL_REGEX = /^[a-zA-Z0-9_-]+$/;
53
+ export const base62Schema = stringSchema.regex(BASE62_REGEX);
54
+ export const base64Schema = stringSchema.regex(BASE64_REGEX);
55
+ export const base64UrlSchema = stringSchema.regex(BASE64URL_REGEX);
56
+ export const JWT_REGEX = /^[\w-]+\.[\w-]+\.[\w-]+$/;
57
+ export const jwtSchema = stringSchema.regex(JWT_REGEX);
71
58
  // 1g498efj5sder3324zer
72
59
  /**
73
60
  * [a-zA-Z0-9_]*
74
61
  * 6-64 length
75
62
  */
76
- exports.idSchema = exports.stringSchema.regex(/^[a-zA-Z0-9_]{6,64}$/);
77
- exports.idBase62Schema = exports.base62Schema.min(8).max(64);
78
- exports.idBase64Schema = exports.base64Schema.min(8).max(64);
79
- exports.idBase64UrlSchema = exports.base64UrlSchema.min(8).max(64);
63
+ export const idSchema = stringSchema.regex(/^[a-zA-Z0-9_]{6,64}$/);
64
+ export const idBase62Schema = base62Schema.min(8).max(64);
65
+ export const idBase64Schema = base64Schema.min(8).max(64);
66
+ export const idBase64UrlSchema = base64UrlSchema.min(8).max(64);
80
67
  /**
81
68
  * `_` should NOT be allowed to be able to use slug-ids as part of natural ids with `_` separator.
82
69
  */
83
- exports.SLUG_REGEX = /^[a-z0-9-]*$/;
70
+ export const SLUG_REGEX = /^[a-z0-9-]*$/;
84
71
  /**
85
72
  * "Slug" - a valid URL, filename, etc.
86
73
  */
87
- exports.slugSchema = exports.stringSchema.regex(exports.SLUG_REGEX).min(1).max(255);
74
+ export const slugSchema = stringSchema.regex(SLUG_REGEX).min(1).max(255);
88
75
  const TS_2500 = 16725225600; // 2500-01-01
89
76
  const TS_2000 = 946684800; // 2000-01-01
90
77
  /**
91
78
  * Between years 1970 and 2050
92
79
  */
93
- exports.unixTimestampSchema = exports.numberSchema
80
+ export const unixTimestampSchema = numberSchema
94
81
  .integer()
95
82
  .min(0)
96
83
  .max(TS_2500);
97
84
  /**
98
85
  * Between years 2000 and 2050
99
86
  */
100
- exports.unixTimestamp2000Schema = exports.numberSchema
87
+ export const unixTimestamp2000Schema = numberSchema
101
88
  .integer()
102
89
  .min(TS_2000)
103
90
  .max(TS_2500);
104
91
  /**
105
92
  * Between years 1970 and 2050
106
93
  */
107
- exports.unixTimestampMillisSchema = exports.numberSchema
94
+ export const unixTimestampMillisSchema = numberSchema
108
95
  .integer()
109
96
  .min(0)
110
97
  .max(TS_2500 * 1000);
111
98
  /**
112
99
  * Between years 2000 and 2050
113
100
  */
114
- exports.unixTimestampMillis2000Schema = exports.numberSchema
101
+ export const unixTimestampMillis2000Schema = numberSchema
115
102
  .integer()
116
103
  .min(TS_2000 * 1000)
117
104
  .max(TS_2500 * 1000);
118
105
  // 2
119
- exports.verSchema = exports.numberSchema.optional().integer().min(1).max(100);
106
+ export const verSchema = numberSchema.optional().integer().min(1).max(100);
120
107
  /**
121
108
  * Be careful, by default emailSchema does TLD validation. To disable it - use `stringSchema.email({tld: false}).lowercase()`
122
109
  */
123
- exports.emailSchema = exports.stringSchema.email().lowercase();
110
+ export const emailSchema = stringSchema.email().lowercase();
124
111
  /**
125
112
  * Pattern is simplified for our use, it's not a canonical SemVer.
126
113
  */
127
- exports.SEM_VER_REGEX = /^[0-9]+\.[0-9]+\.[0-9]+$/;
128
- exports.semVerSchema = exports.stringSchema.regex(exports.SEM_VER_REGEX);
114
+ export const SEM_VER_REGEX = /^[0-9]+\.[0-9]+\.[0-9]+$/;
115
+ export const semVerSchema = stringSchema.regex(SEM_VER_REGEX);
129
116
  // todo: .error(() => 'should be SemVer')
130
- exports.userAgentSchema = exports.stringSchema
117
+ export const userAgentSchema = stringSchema
131
118
  .min(5) // I've seen UA of `Android` (7 characters)
132
119
  .max(400);
133
- exports.utcOffsetSchema = exports.numberSchema
120
+ export const utcOffsetSchema = numberSchema
134
121
  .min(-14 * 60)
135
122
  .max(14 * 60)
136
123
  .dividable(15);
137
- exports.ianaTimezoneSchema = exports.stringSchema
124
+ export const ianaTimezoneSchema = stringSchema
138
125
  // UTC is added to assist unit-testing, which uses UTC by default (not technically a valid Iana timezone identifier)
139
126
  .valid(...Intl.supportedValuesOf('timeZone'), 'UTC')
140
127
  .messages({
141
128
  'any.only': `must be a valid IANA timezone string`,
142
129
  });
143
- exports.ipAddressSchema = exports.stringSchema.ip();
144
- exports.baseDBEntitySchema = objectSchema({
145
- id: exports.stringSchema.optional(),
146
- created: exports.unixTimestamp2000Schema.optional(),
147
- updated: exports.unixTimestamp2000Schema.optional(),
130
+ export const ipAddressSchema = stringSchema.ip();
131
+ export const baseDBEntitySchema = objectSchema({
132
+ id: stringSchema.optional(),
133
+ created: unixTimestamp2000Schema.optional(),
134
+ updated: unixTimestamp2000Schema.optional(),
148
135
  });
149
- exports.macAddressSchema = exports.stringSchema.regex(/^([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})$/);
150
- exports.uuidSchema = exports.stringSchema.uuid();
136
+ export const macAddressSchema = stringSchema.regex(/^([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})$/);
137
+ export const uuidSchema = stringSchema.uuid();
@@ -1,12 +1,8 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.JoiValidationError = void 0;
4
- const js_lib_1 = require("@naturalcycles/js-lib");
5
- class JoiValidationError extends js_lib_1.AppError {
1
+ import { AppError } from '@naturalcycles/js-lib';
2
+ export class JoiValidationError extends AppError {
6
3
  constructor(message, data) {
7
4
  super(message, data, {
8
5
  name: 'JoiValidationError',
9
6
  });
10
7
  }
11
8
  }
12
- exports.JoiValidationError = JoiValidationError;
@@ -1,5 +1,5 @@
1
1
  import type { AnySchema, ValidationOptions } from 'joi';
2
- import { JoiValidationError } from './joi.validation.error';
2
+ import { JoiValidationError } from './joi.validation.error.js';
3
3
  export interface JoiValidationResult<T = any> {
4
4
  value: T;
5
5
  error?: JoiValidationError;