@naturalcycles/js-lib 14.128.1 → 14.130.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 (73) hide show
  1. package/dist/decorators/asyncMemo.decorator.d.ts +2 -2
  2. package/dist/decorators/createPromiseDecorator.d.ts +6 -6
  3. package/dist/decorators/debounce.d.ts +2 -2
  4. package/dist/decorators/memo.decorator.d.ts +2 -2
  5. package/dist/decorators/memo.util.d.ts +7 -7
  6. package/dist/error/app.error.d.ts +1 -1
  7. package/dist/error/app.error.js +2 -2
  8. package/dist/error/assert.d.ts +0 -1
  9. package/dist/error/assert.js +0 -3
  10. package/dist/error/error.model.d.ts +1 -0
  11. package/dist/error/error.util.d.ts +4 -4
  12. package/dist/error/error.util.js +26 -13
  13. package/dist/error/errorMode.d.ts +1 -1
  14. package/dist/error/errorMode.js +1 -1
  15. package/dist/error/http.error.d.ts +1 -1
  16. package/dist/error/http.error.js +2 -2
  17. package/dist/error/tryCatch.d.ts +1 -1
  18. package/dist/http/fetcher.js +4 -3
  19. package/dist/index.d.ts +6 -3
  20. package/dist/index.js +9 -4
  21. package/dist/json-schema/jsonSchemaBuilder.d.ts +1 -1
  22. package/dist/promise/pDefer.d.ts +2 -2
  23. package/dist/promise/pMap.js +3 -4
  24. package/dist/promise/pRetry.d.ts +1 -1
  25. package/dist/promise/pTimeout.d.ts +1 -1
  26. package/dist/string/pupa.d.ts +2 -2
  27. package/dist/string/readingTime.d.ts +1 -1
  28. package/dist/string/stringifyAny.d.ts +6 -0
  29. package/dist/string/stringifyAny.js +13 -1
  30. package/dist/zod/zod.shared.schemas.d.ts +52 -0
  31. package/dist/zod/zod.shared.schemas.js +94 -0
  32. package/dist/zod/zod.util.d.ts +21 -0
  33. package/dist/zod/zod.util.js +59 -0
  34. package/dist-esm/error/app.error.js +2 -2
  35. package/dist-esm/error/assert.js +0 -3
  36. package/dist-esm/error/error.util.js +26 -11
  37. package/dist-esm/error/errorMode.js +1 -1
  38. package/dist-esm/error/http.error.js +2 -2
  39. package/dist-esm/http/fetcher.js +4 -3
  40. package/dist-esm/index.js +5 -3
  41. package/dist-esm/promise/pMap.js +3 -4
  42. package/dist-esm/string/stringifyAny.js +13 -1
  43. package/dist-esm/zod/zod.shared.schemas.js +91 -0
  44. package/dist-esm/zod/zod.util.js +53 -0
  45. package/package.json +3 -2
  46. package/src/decorators/asyncMemo.decorator.ts +2 -2
  47. package/src/decorators/createPromiseDecorator.ts +4 -4
  48. package/src/decorators/debounce.ts +2 -2
  49. package/src/decorators/memo.decorator.ts +2 -2
  50. package/src/decorators/memo.util.ts +7 -7
  51. package/src/error/app.error.ts +2 -2
  52. package/src/error/assert.ts +1 -5
  53. package/src/error/error.model.ts +10 -0
  54. package/src/error/error.util.ts +26 -21
  55. package/src/error/errorMode.ts +1 -1
  56. package/src/error/http.error.ts +2 -2
  57. package/src/error/tryCatch.ts +1 -1
  58. package/src/http/fetcher.ts +5 -8
  59. package/src/index.ts +6 -3
  60. package/src/json-schema/jsonSchemaBuilder.ts +1 -1
  61. package/src/promise/pDefer.ts +2 -2
  62. package/src/promise/pMap.ts +3 -4
  63. package/src/promise/pRetry.ts +1 -1
  64. package/src/promise/pTimeout.ts +1 -1
  65. package/src/string/pupa.ts +1 -1
  66. package/src/string/readingTime.ts +1 -1
  67. package/src/string/stringifyAny.ts +23 -1
  68. package/src/zod/zod.shared.schemas.ts +102 -0
  69. package/src/zod/zod.util.ts +77 -0
  70. package/dist/promise/AggregatedError.d.ts +0 -10
  71. package/dist/promise/AggregatedError.js +0 -34
  72. package/dist-esm/promise/AggregatedError.js +0 -30
  73. package/src/promise/AggregatedError.ts +0 -36
@@ -6,11 +6,11 @@ export interface AsyncMemoOptions {
6
6
  * Function that creates an instance of `MemoCache`.
7
7
  * e.g LRUMemoCache from `@naturalcycles/nodejs-lib`.
8
8
  */
9
- cacheFactory?(): AsyncMemoCache;
9
+ cacheFactory?: () => AsyncMemoCache;
10
10
  /**
11
11
  * Provide a custom implementation of CacheKey function.
12
12
  */
13
- cacheKeyFn?(args: any[]): any;
13
+ cacheKeyFn?: (args: any[]) => any;
14
14
  /**
15
15
  * Default true.
16
16
  *
@@ -4,15 +4,15 @@ export interface PromiseDecoratorCfg<RES = any, PARAMS = any> {
4
4
  * Called BEFORE the original function.
5
5
  * If Promise is returned - it will be awaited.
6
6
  */
7
- beforeFn?(r: PromiseDecoratorResp<PARAMS>): void | Promise<void>;
7
+ beforeFn?: (r: PromiseDecoratorResp<PARAMS>) => void | Promise<void>;
8
8
  /**
9
9
  * Called just AFTER the original function.
10
10
  * The output of this hook will be passed further,
11
11
  * so, pay attention to pass through (or modify) the result.
12
12
  */
13
- thenFn?(r: PromiseDecoratorResp<PARAMS> & {
13
+ thenFn?: (r: PromiseDecoratorResp<PARAMS> & {
14
14
  res: RES;
15
- }): RES;
15
+ }) => RES;
16
16
  /**
17
17
  * Called on Promise.reject.
18
18
  * If `catchFn` is not present - will re-throw the error,
@@ -20,14 +20,14 @@ export interface PromiseDecoratorCfg<RES = any, PARAMS = any> {
20
20
  * If `catchFn` is present - it's responsible for handling or re-throwing the error.
21
21
  * Whatever `catchFn` returns - passed to the original output.
22
22
  */
23
- catchFn?(r: PromiseDecoratorResp<PARAMS> & {
23
+ catchFn?: (r: PromiseDecoratorResp<PARAMS> & {
24
24
  err: any;
25
- }): RES;
25
+ }) => RES;
26
26
  /**
27
27
  * Fires AFTER thenFn / catchFn, like a usual Promise.finally().
28
28
  * Doesn't have access to neither res nor err (same as Promise.finally).
29
29
  */
30
- finallyFn?(r: PromiseDecoratorResp<PARAMS>): any;
30
+ finallyFn?: (r: PromiseDecoratorResp<PARAMS>) => any;
31
31
  }
32
32
  export interface PromiseDecoratorResp<PARAMS> {
33
33
  decoratorParams: PARAMS;
@@ -1,7 +1,7 @@
1
1
  import type { AnyFunction } from '../types';
2
2
  export interface Cancelable {
3
- cancel(): void;
4
- flush(): void;
3
+ cancel: () => void;
4
+ flush: () => void;
5
5
  }
6
6
  export interface ThrottleOptions {
7
7
  /**
@@ -6,11 +6,11 @@ export interface MemoOptions {
6
6
  * Function that creates an instance of `MemoCache`.
7
7
  * e.g LRUMemoCache from `@naturalcycles/nodejs-lib`
8
8
  */
9
- cacheFactory?(): MemoCache;
9
+ cacheFactory?: () => MemoCache;
10
10
  /**
11
11
  * Provide a custom implementation of CacheKey function.
12
12
  */
13
- cacheKeyFn?(args: any[]): any;
13
+ cacheKeyFn?: (args: any[]) => any;
14
14
  /**
15
15
  * Defaults to true.
16
16
  * Set to false to skip caching errors.
@@ -2,14 +2,14 @@ import type { Promisable } from '../typeFest';
2
2
  export type MemoSerializer = (args: any[]) => any;
3
3
  export declare const jsonMemoSerializer: MemoSerializer;
4
4
  export interface MemoCache<KEY = any, VALUE = any> {
5
- has(k: KEY): boolean;
6
- get(k: KEY): VALUE | Error | undefined;
7
- set(k: KEY, v: VALUE | Error): void;
5
+ has: (k: KEY) => boolean;
6
+ get: (k: KEY) => VALUE | Error | undefined;
7
+ set: (k: KEY, v: VALUE | Error) => void;
8
8
  /**
9
9
  * Clear is only called when `.dropCache()` is called.
10
10
  * Otherwise the Cache is "persistent" (never cleared).
11
11
  */
12
- clear(): void;
12
+ clear: () => void;
13
13
  }
14
14
  export interface AsyncMemoCache<KEY = any, VALUE = any> {
15
15
  /**
@@ -17,13 +17,13 @@ export interface AsyncMemoCache<KEY = any, VALUE = any> {
17
17
  * This also means that you CANNOT store `undefined` value in the Cache, as it'll be treated as a MISS.
18
18
  * You CAN store `null` value instead, it will be treated as a HIT.
19
19
  */
20
- get(k: KEY): Promisable<VALUE | Error | undefined>;
21
- set(k: KEY, v: VALUE | Error): Promisable<void>;
20
+ get: (k: KEY) => Promisable<VALUE | Error | undefined>;
21
+ set: (k: KEY, v: VALUE | Error) => Promisable<void>;
22
22
  /**
23
23
  * Clear is only called when `.dropCache()` is called.
24
24
  * Otherwise the Cache is "persistent" (never cleared).
25
25
  */
26
- clear(): Promisable<void>;
26
+ clear: () => Promisable<void>;
27
27
  }
28
28
  export declare class MapMemoCache<KEY = any, VALUE = any> implements MemoCache<KEY, VALUE>, AsyncMemoCache<KEY, VALUE> {
29
29
  private m;
@@ -10,5 +10,5 @@ import type { ErrorData } from './error.model';
10
10
  */
11
11
  export declare class AppError<DATA_TYPE extends ErrorData = ErrorData> extends Error {
12
12
  data: DATA_TYPE;
13
- constructor(message: string, data?: DATA_TYPE);
13
+ constructor(message: string, data?: DATA_TYPE, opt?: ErrorOptions);
14
14
  }
@@ -11,8 +11,8 @@ exports.AppError = void 0;
11
11
  * Based on: https://medium.com/@xpl/javascript-deriving-from-error-properly-8d2f8f315801
12
12
  */
13
13
  class AppError extends Error {
14
- constructor(message, data = {}) {
15
- super(message);
14
+ constructor(message, data = {}, opt) {
15
+ super(message, opt);
16
16
  Object.defineProperty(this, 'name', {
17
17
  value: this.constructor.name,
18
18
  configurable: true,
@@ -36,5 +36,4 @@ export declare function _assertIsString(v: any, message?: string): asserts v is
36
36
  export declare function _assertIsNumber(v: any, message?: string): asserts v is number;
37
37
  export declare function _assertTypeOf<T>(v: any, expectedType: string, message?: string): asserts v is T;
38
38
  export declare class AssertionError extends AppError {
39
- constructor(message: string, data?: ErrorData);
40
39
  }
@@ -103,8 +103,5 @@ function _assertTypeOf(v, expectedType, message) {
103
103
  }
104
104
  exports._assertTypeOf = _assertTypeOf;
105
105
  class AssertionError extends app_error_1.AppError {
106
- constructor(message, data = {}) {
107
- super(message, data);
108
- }
109
106
  }
110
107
  exports.AssertionError = AssertionError;
@@ -93,6 +93,7 @@ export interface ErrorObject<DATA_TYPE extends ErrorData = ErrorData> {
93
93
  * It's non-optional, to save some null-checks.
94
94
  */
95
95
  data: DATA_TYPE;
96
+ cause?: any;
96
97
  }
97
98
  /**
98
99
  * JSON HTTP response from the Backend that represents "Error".
@@ -1,4 +1,4 @@
1
- import type { ErrorData, ErrorObject, HttpErrorData, HttpErrorResponse, StringifyAnyOptions, Class } from '..';
1
+ import type { ErrorData, ErrorObject, HttpErrorData, HttpErrorResponse, Class } from '..';
2
2
  import { AppError } from '..';
3
3
  /**
4
4
  * Useful to ensure that error in `catch (err) { ... }`
@@ -8,15 +8,15 @@ import { AppError } from '..';
8
8
  *
9
9
  * Alternatively, if you're sure it's Error - you can use `_assertIsError(err)`.
10
10
  */
11
- export declare function _anyToError<ERROR_TYPE extends Error = Error>(o: any, errorClass?: Class<ERROR_TYPE>, errorData?: ErrorData, opt?: StringifyAnyOptions): ERROR_TYPE;
11
+ export declare function _anyToError<ERROR_TYPE extends Error = Error>(o: any, errorClass?: Class<ERROR_TYPE>, errorData?: ErrorData): ERROR_TYPE;
12
12
  /**
13
13
  * Converts "anything" to ErrorObject.
14
14
  * Detects if it's HttpErrorResponse, HttpErrorObject, ErrorObject, Error, etc..
15
15
  * If object is Error - Error.message will be used.
16
16
  * Objects (not Errors) get converted to prettified JSON string (via `_stringifyAny`).
17
17
  */
18
- export declare function _anyToErrorObject<DATA_TYPE extends ErrorData = ErrorData>(o: any, errorData?: Partial<DATA_TYPE>, opt?: StringifyAnyOptions): ErrorObject<DATA_TYPE>;
19
- export declare function _errorToErrorObject<DATA_TYPE extends ErrorData = ErrorData>(e: AppError<DATA_TYPE> | Error, includeErrorStack?: boolean): ErrorObject<DATA_TYPE>;
18
+ export declare function _anyToErrorObject<DATA_TYPE extends ErrorData = ErrorData>(o: any, errorData?: Partial<DATA_TYPE>): ErrorObject<DATA_TYPE>;
19
+ export declare function _errorToErrorObject<DATA_TYPE extends ErrorData = ErrorData>(e: AppError<DATA_TYPE> | Error): ErrorObject<DATA_TYPE>;
20
20
  export declare function _errorObjectToAppError<DATA_TYPE extends ErrorData>(o: ErrorObject<DATA_TYPE>): AppError<DATA_TYPE>;
21
21
  export declare function _errorObjectToError<DATA_TYPE extends ErrorData, ERROR_TYPE extends Error>(o: ErrorObject<DATA_TYPE>, errorClass?: Class<ERROR_TYPE>): ERROR_TYPE;
22
22
  export declare function _isHttpErrorResponse(o: any): o is HttpErrorResponse;
@@ -10,14 +10,14 @@ const __1 = require("..");
10
10
  *
11
11
  * Alternatively, if you're sure it's Error - you can use `_assertIsError(err)`.
12
12
  */
13
- function _anyToError(o, errorClass = Error, errorData, opt) {
13
+ function _anyToError(o, errorClass = Error, errorData) {
14
14
  let e;
15
15
  if (o instanceof errorClass) {
16
16
  e = o;
17
17
  }
18
18
  else {
19
19
  // If it's an instance of Error, but ErrorClass is something else (e.g AppError) - it'll be "repacked" into AppError
20
- const errorObject = _isErrorObject(o) ? o : _anyToErrorObject(o, {}, opt);
20
+ const errorObject = _anyToErrorObject(o);
21
21
  e = _errorObjectToError(errorObject, errorClass);
22
22
  }
23
23
  if (errorData) {
@@ -36,10 +36,10 @@ exports._anyToError = _anyToError;
36
36
  * If object is Error - Error.message will be used.
37
37
  * Objects (not Errors) get converted to prettified JSON string (via `_stringifyAny`).
38
38
  */
39
- function _anyToErrorObject(o, errorData, opt) {
39
+ function _anyToErrorObject(o, errorData) {
40
40
  let eo;
41
41
  if (o instanceof Error) {
42
- eo = _errorToErrorObject(o, opt?.includeErrorStack ?? true);
42
+ eo = _errorToErrorObject(o);
43
43
  }
44
44
  else {
45
45
  o = (0, __1._jsonParseIfPossible)(o);
@@ -54,10 +54,7 @@ function _anyToErrorObject(o, errorData, opt) {
54
54
  // so, fair to return `data: {}` in the end
55
55
  // Also we're sure it includes no "error name", e.g no `Error: ...`,
56
56
  // so, fair to include `name: 'Error'`
57
- const message = (0, __1._stringifyAny)(o, {
58
- includeErrorData: true,
59
- ...opt,
60
- });
57
+ const message = (0, __1._stringifyAny)(o);
61
58
  eo = {
62
59
  name: 'Error',
63
60
  message,
@@ -69,14 +66,15 @@ function _anyToErrorObject(o, errorData, opt) {
69
66
  return eo;
70
67
  }
71
68
  exports._anyToErrorObject = _anyToErrorObject;
72
- function _errorToErrorObject(e, includeErrorStack = true) {
69
+ function _errorToErrorObject(e) {
73
70
  const obj = {
74
71
  name: e.name,
75
72
  message: e.message,
76
- data: { ...e.data }, // empty by default
73
+ data: { ...e.data },
74
+ stack: e.stack,
77
75
  };
78
- if (includeErrorStack) {
79
- obj.stack = e.stack;
76
+ if (e.cause) {
77
+ obj.cause = _anyToErrorObject(e.cause);
80
78
  }
81
79
  return obj;
82
80
  }
@@ -106,6 +104,14 @@ function _errorObjectToError(o, errorClass = Error) {
106
104
  value: o.stack,
107
105
  });
108
106
  }
107
+ if (o.cause) {
108
+ Object.defineProperty(err, 'cause', {
109
+ value: o.cause,
110
+ writable: true,
111
+ configurable: true,
112
+ enumerable: false,
113
+ });
114
+ }
109
115
  return err;
110
116
  }
111
117
  exports._errorObjectToError = _errorObjectToError;
@@ -124,9 +130,16 @@ exports._isHttpErrorObject = _isHttpErrorObject;
124
130
  * Note: any instance of AppError is also automatically an ErrorObject
125
131
  */
126
132
  function _isErrorObject(o) {
127
- return (!!o && typeof o.name === 'string' && typeof o.message === 'string' && typeof o.data === 'object');
133
+ return (!!o &&
134
+ typeof o === 'object' &&
135
+ typeof o.name === 'string' &&
136
+ typeof o.message === 'string' &&
137
+ typeof o.data === 'object');
128
138
  }
129
139
  exports._isErrorObject = _isErrorObject;
140
+ // export function _isErrorLike(o: any): o is ErrorLike {
141
+ // return !!o && typeof o === 'object' && typeof o.name === 'string' && typeof o.message === 'string'
142
+ // }
130
143
  /**
131
144
  * Convenience function to safely add properties to Error's `data` object
132
145
  * (even if it wasn't previously existing)
@@ -9,7 +9,7 @@ export declare enum ErrorMode {
9
9
  */
10
10
  THROW_IMMEDIATELY = "THROW_IMMEDIATELY",
11
11
  /**
12
- * Don't throw on errors, but collect them and throw as AggregatedError in the end.
12
+ * Don't throw on errors, but collect them and throw as AggregateError in the end.
13
13
  */
14
14
  THROW_AGGREGATED = "THROW_AGGREGATED",
15
15
  /**
@@ -13,7 +13,7 @@ var ErrorMode;
13
13
  */
14
14
  ErrorMode["THROW_IMMEDIATELY"] = "THROW_IMMEDIATELY";
15
15
  /**
16
- * Don't throw on errors, but collect them and throw as AggregatedError in the end.
16
+ * Don't throw on errors, but collect them and throw as AggregateError in the end.
17
17
  */
18
18
  ErrorMode["THROW_AGGREGATED"] = "THROW_AGGREGATED";
19
19
  /**
@@ -4,5 +4,5 @@ import type { HttpErrorData } from './error.model';
4
4
  * Base class for HTTP errors - errors that define HTTP error code.
5
5
  */
6
6
  export declare class HttpError<DATA_TYPE extends HttpErrorData = HttpErrorData> extends AppError<DATA_TYPE> {
7
- constructor(message: string, data: DATA_TYPE);
7
+ constructor(message: string, data: DATA_TYPE, opt?: ErrorOptions);
8
8
  }
@@ -6,8 +6,8 @@ const app_error_1 = require("./app.error");
6
6
  * Base class for HTTP errors - errors that define HTTP error code.
7
7
  */
8
8
  class HttpError extends app_error_1.AppError {
9
- constructor(message, data) {
10
- super(message, data);
9
+ constructor(message, data, opt) {
10
+ super(message, data, opt);
11
11
  }
12
12
  }
13
13
  exports.HttpError = HttpError;
@@ -5,7 +5,7 @@ export interface TryCatchOptions {
5
5
  * The value returned from the function will be returned from the wrapped method (!).
6
6
  * onError function may be asynchronous.
7
7
  */
8
- onError?(err: Error): any;
8
+ onError?: (err: Error) => any;
9
9
  /**
10
10
  * @default false
11
11
  */
@@ -151,11 +151,12 @@ class Fetcher {
151
151
  res.body = JSON.parse(text, req.jsonReviver);
152
152
  }
153
153
  catch (err) {
154
- res.ok = false;
155
- res.err = (0, error_util_1._anyToError)(err, http_error_1.HttpError, (0, object_util_1._filterNullishValues)({
154
+ const { message } = (0, error_util_1._anyToError)(err);
155
+ res.err = new http_error_1.HttpError([signature, message].join('\n'), {
156
156
  httpStatusCode: 0,
157
157
  url: req.url,
158
- }));
158
+ });
159
+ res.ok = false;
159
160
  }
160
161
  }
161
162
  else {
package/dist/index.d.ts CHANGED
@@ -37,7 +37,6 @@ export * from './object/deepEquals';
37
37
  export * from './object/object.util';
38
38
  export * from './object/sortObject';
39
39
  export * from './object/sortObjectDeep';
40
- export * from './promise/AggregatedError';
41
40
  export * from './promise/pDefer';
42
41
  export * from './promise/pDelay';
43
42
  export * from './promise/pFilter';
@@ -59,7 +58,6 @@ export * from './is.util';
59
58
  export * from './typeFest';
60
59
  export * from './types';
61
60
  export * from './unit/size.util';
62
- import { is } from './vendor/is';
63
61
  export * from './log/commonLogger';
64
62
  export * from './string/safeJsonStringify';
65
63
  export * from './promise/pQueue';
@@ -77,4 +75,9 @@ export * from './datetime/timeInterval';
77
75
  export * from './http/http.model';
78
76
  export * from './http/fetcher';
79
77
  export * from './http/fetcher.model';
80
- export { is };
78
+ export * from './zod/zod.util';
79
+ export * from './zod/zod.shared.schemas';
80
+ import { z, ZodSchema, ZodError, ZodIssue } from 'zod';
81
+ import { is } from './vendor/is';
82
+ export { is, z, ZodSchema, ZodError };
83
+ export type { ZodIssue };
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.is = void 0;
3
+ exports.ZodError = exports.ZodSchema = exports.z = exports.is = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  tslib_1.__exportStar(require("./array/array.util"), exports);
6
6
  tslib_1.__exportStar(require("./lazy"), exports);
@@ -41,7 +41,6 @@ tslib_1.__exportStar(require("./object/deepEquals"), exports);
41
41
  tslib_1.__exportStar(require("./object/object.util"), exports);
42
42
  tslib_1.__exportStar(require("./object/sortObject"), exports);
43
43
  tslib_1.__exportStar(require("./object/sortObjectDeep"), exports);
44
- tslib_1.__exportStar(require("./promise/AggregatedError"), exports);
45
44
  tslib_1.__exportStar(require("./promise/pDefer"), exports);
46
45
  tslib_1.__exportStar(require("./promise/pDelay"), exports);
47
46
  tslib_1.__exportStar(require("./promise/pFilter"), exports);
@@ -63,8 +62,6 @@ tslib_1.__exportStar(require("./is.util"), exports);
63
62
  tslib_1.__exportStar(require("./typeFest"), exports);
64
63
  tslib_1.__exportStar(require("./types"), exports);
65
64
  tslib_1.__exportStar(require("./unit/size.util"), exports);
66
- const is_1 = require("./vendor/is");
67
- Object.defineProperty(exports, "is", { enumerable: true, get: function () { return is_1.is; } });
68
65
  tslib_1.__exportStar(require("./log/commonLogger"), exports);
69
66
  tslib_1.__exportStar(require("./string/safeJsonStringify"), exports);
70
67
  tslib_1.__exportStar(require("./promise/pQueue"), exports);
@@ -82,3 +79,11 @@ tslib_1.__exportStar(require("./datetime/timeInterval"), exports);
82
79
  tslib_1.__exportStar(require("./http/http.model"), exports);
83
80
  tslib_1.__exportStar(require("./http/fetcher"), exports);
84
81
  tslib_1.__exportStar(require("./http/fetcher.model"), exports);
82
+ tslib_1.__exportStar(require("./zod/zod.util"), exports);
83
+ tslib_1.__exportStar(require("./zod/zod.shared.schemas"), exports);
84
+ const zod_1 = require("zod");
85
+ Object.defineProperty(exports, "z", { enumerable: true, get: function () { return zod_1.z; } });
86
+ Object.defineProperty(exports, "ZodSchema", { enumerable: true, get: function () { return zod_1.ZodSchema; } });
87
+ Object.defineProperty(exports, "ZodError", { enumerable: true, get: function () { return zod_1.ZodError; } });
88
+ const is_1 = require("./vendor/is");
89
+ Object.defineProperty(exports, "is", { enumerable: true, get: function () { return is_1.is; } });
@@ -2,7 +2,7 @@
2
2
  import type { BaseDBEntity, JsonSchemaAllOf, JsonSchemaArray, JsonSchemaOneOf, JsonSchemaTuple, SavedDBEntity, AnyObject } from '../index';
3
3
  import type { JsonSchema, JsonSchemaAny, JsonSchemaBoolean, JsonSchemaConst, JsonSchemaEnum, JsonSchemaNull, JsonSchemaNumber, JsonSchemaObject, JsonSchemaRef, JsonSchemaString } from './jsonSchema.model';
4
4
  export interface JsonSchemaBuilder<T = unknown> {
5
- build(): JsonSchema<T>;
5
+ build: () => JsonSchema<T>;
6
6
  }
7
7
  /**
8
8
  * Fluent (chainable) API to manually create Json Schemas.
@@ -2,8 +2,8 @@
2
2
  * Similar to Deferred object, which is also a promise itself (instead of deferred.promise).
3
3
  */
4
4
  export interface DeferredPromise<T = void> extends Promise<T> {
5
- resolve(a?: T): void;
6
- reject(e?: Error): void;
5
+ resolve: (a?: T) => void;
6
+ reject: (e?: Error) => void;
7
7
  }
8
8
  /**
9
9
  * Returns DeferredPromise - a Promise that has .resolve() and .reject() methods.
@@ -10,7 +10,6 @@ Improvements:
10
10
  Object.defineProperty(exports, "__esModule", { value: true });
11
11
  exports.pMap = void 0;
12
12
  const __1 = require("..");
13
- const AggregatedError_1 = require("./AggregatedError");
14
13
  /**
15
14
  * Returns a `Promise` that is fulfilled when all promises in `input` and ones returned from `mapper` are fulfilled,
16
15
  * or rejects if any of the promises reject. The fulfilled value is an `Array` of the fulfilled values returned
@@ -70,7 +69,7 @@ async function pMap(iterable, mapper, opt = {}) {
70
69
  }
71
70
  }
72
71
  if (errors.length) {
73
- throw new AggregatedError_1.AggregatedError(errors, ret);
72
+ throw new AggregateError(errors, `pMap resulted in ${errors.length} error(s)`);
74
73
  }
75
74
  return ret;
76
75
  }
@@ -90,7 +89,7 @@ async function pMap(iterable, mapper, opt = {}) {
90
89
  }
91
90
  });
92
91
  if (errors.length) {
93
- throw new AggregatedError_1.AggregatedError(errors, ret);
92
+ throw new AggregateError(errors, `pMap resulted in ${errors.length} error(s)`);
94
93
  }
95
94
  return ret;
96
95
  }
@@ -106,7 +105,7 @@ async function pMap(iterable, mapper, opt = {}) {
106
105
  isSettled = true;
107
106
  const r = ret.filter(r => r !== __1.SKIP);
108
107
  if (errors.length) {
109
- reject(new AggregatedError_1.AggregatedError(errors, r));
108
+ reject(new AggregateError(errors, `pMap resulted in ${errors.length} error(s)`));
110
109
  }
111
110
  else {
112
111
  resolve(r);
@@ -35,7 +35,7 @@ export interface PRetryOptions {
35
35
  *
36
36
  * @default () => true
37
37
  */
38
- predicate?(err: Error, attempt: number, maxAttempts: number): boolean;
38
+ predicate?: (err: Error, attempt: number, maxAttempts: number) => boolean;
39
39
  /**
40
40
  * Log the first attempt (which is not a "retry" yet).
41
41
  *
@@ -20,7 +20,7 @@ export interface PTimeoutOptions {
20
20
  * err (which is TimeoutError) is passed as an argument for convenience, so it can
21
21
  * be logged or such. You don't have to consume it in any way though.
22
22
  */
23
- onTimeout?(err: TimeoutError): any;
23
+ onTimeout?: (err: TimeoutError) => any;
24
24
  /**
25
25
  * Defaults to true.
26
26
  * If true - preserves the stack trace in case of a Timeout (usually - very useful!).
@@ -11,10 +11,10 @@ export interface PupaOptions {
11
11
  /**
12
12
  * Performs arbitrary operation for each interpolation. If the returned value was `undefined`, it behaves differently depending on the `ignoreMissing` option. Otherwise, the returned value will be interpolated into a string (and escaped when double-braced) and embedded into the template.
13
13
  */
14
- transform?(data: {
14
+ transform?: (data: {
15
15
  value: any;
16
16
  key: string;
17
- }): unknown;
17
+ }) => unknown;
18
18
  }
19
19
  /**
20
20
  * API: https://github.com/sindresorhus/pupa
@@ -4,7 +4,7 @@ export interface ReadingTimeOptions {
4
4
  * A function that returns a boolean value depending on if a character is considered as a word bound.
5
5
  * Default: spaces, new lines and tabs
6
6
  */
7
- wordBound?(char: string): boolean;
7
+ wordBound?: (char: string) => boolean;
8
8
  /**
9
9
  * Default 200
10
10
  */
@@ -32,6 +32,12 @@ export interface StringifyAnyOptions {
32
32
  * @default false
33
33
  */
34
34
  includeErrorStack?: boolean;
35
+ /**
36
+ * Set to false to skip including Error.cause.
37
+ *
38
+ * @default true
39
+ */
40
+ includeErrorCause?: boolean;
35
41
  /**
36
42
  * Allows to pass custom "stringify function".
37
43
  * E.g in Node.js you can pass `util.inspect` instead.
@@ -4,6 +4,7 @@ exports._stringifyAny = exports.setGlobalStringifyFunction = void 0;
4
4
  const error_util_1 = require("../error/error.util");
5
5
  const json_util_1 = require("./json.util");
6
6
  const safeJsonStringify_1 = require("./safeJsonStringify");
7
+ const supportsAggregateError = typeof globalThis.AggregateError === 'function';
7
8
  let globalStringifyFunction = safeJsonStringify_1._safeJsonStringify;
8
9
  /**
9
10
  * Allows to set Global "stringifyFunction" that will be used to "pretty-print" objects
@@ -59,6 +60,7 @@ function _stringifyAny(obj, opt = {}) {
59
60
  return _stringifyAny(obj.error, opt);
60
61
  }
61
62
  if (obj instanceof Error || (0, error_util_1._isErrorObject)(obj)) {
63
+ const { includeErrorCause = true } = opt;
62
64
  //
63
65
  // Error or ErrorObject
64
66
  //
@@ -67,7 +69,7 @@ function _stringifyAny(obj, opt = {}) {
67
69
  // if (obj?.name === 'Error') {
68
70
  // s = obj.message
69
71
  // }
70
- s = [obj.name, obj.message].join(': ');
72
+ s = [obj.name, obj.message].filter(Boolean).join(': ');
71
73
  if (opt.includeErrorStack && obj.stack) {
72
74
  // Here we're using the previously-generated "title line" (e.g "Error: some_message"),
73
75
  // concatenating it with the Stack (but without the title line of the Stack)
@@ -92,6 +94,16 @@ function _stringifyAny(obj, opt = {}) {
92
94
  // Error that has no `data`, but has `code` property
93
95
  s = [s, `code: ${obj.code}`].join('\n');
94
96
  }
97
+ if (supportsAggregateError && obj instanceof AggregateError && obj.errors.length) {
98
+ s = [
99
+ s,
100
+ `${obj.errors.length} error(s):`,
101
+ ...obj.errors.map((err, i) => `${i + 1}. ${_stringifyAny(err, opt)}`),
102
+ ].join('\n');
103
+ }
104
+ if (obj.cause && includeErrorCause) {
105
+ s = s + '\ncaused by: ' + _stringifyAny(obj.cause, opt);
106
+ }
95
107
  }
96
108
  else if (typeof obj === 'string') {
97
109
  //
@@ -0,0 +1,52 @@
1
+ import { z } from 'zod';
2
+ export declare const TS_2500 = 16725225600;
3
+ export declare const TS_2000 = 946684800;
4
+ export declare const zUnixTimestamp: z.ZodNumber;
5
+ export declare const zUnixTimestamp2000: z.ZodNumber;
6
+ export declare const zUnixTimestampMillis: z.ZodNumber;
7
+ export declare const zUnixTimestampMillis2000: z.ZodNumber;
8
+ export declare const zSemVer: z.ZodString;
9
+ export declare const zIsoDateString: z.ZodEffects<z.ZodString, string, string>;
10
+ export declare const zEmail: z.ZodEffects<z.ZodString, string, string>;
11
+ export declare const BASE62_REGEX: RegExp;
12
+ export declare const BASE64_REGEX: RegExp;
13
+ export declare const BASE64URL_REGEX: RegExp;
14
+ export declare const zBase62: z.ZodString;
15
+ export declare const zBase64: z.ZodString;
16
+ export declare const zBase64Url: z.ZodString;
17
+ export declare const JWT_REGEX: RegExp;
18
+ export declare const zJwt: z.ZodString;
19
+ export declare const zId: z.ZodString;
20
+ export declare const zIdBase62: z.ZodString;
21
+ export declare const zIdBase64: z.ZodString;
22
+ export declare const zIdBase64Url: z.ZodString;
23
+ /**
24
+ * "Slug" - a valid URL, filename, etc.
25
+ */
26
+ export declare const zSlug: z.ZodString;
27
+ export declare const zBaseDBEntity: z.ZodObject<{
28
+ id: z.ZodOptional<z.ZodString>;
29
+ created: z.ZodOptional<z.ZodNumber>;
30
+ updated: z.ZodOptional<z.ZodNumber>;
31
+ }, "strip", z.ZodTypeAny, {
32
+ id?: string | undefined;
33
+ created?: number | undefined;
34
+ updated?: number | undefined;
35
+ }, {
36
+ id?: string | undefined;
37
+ created?: number | undefined;
38
+ updated?: number | undefined;
39
+ }>;
40
+ export declare const zSavedDBEntity: z.ZodObject<{
41
+ id: z.ZodString;
42
+ created: z.ZodNumber;
43
+ updated: z.ZodNumber;
44
+ }, "strip", z.ZodTypeAny, {
45
+ id: string;
46
+ created: number;
47
+ updated: number;
48
+ }, {
49
+ id: string;
50
+ created: number;
51
+ updated: number;
52
+ }>;