@naturalcycles/js-lib 15.16.2 → 15.18.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/array/index.d.ts +2 -0
- package/dist/array/index.js +2 -0
- package/dist/browser/analytics.util.js +1 -1
- package/dist/decorators/logMethod.decorator.d.ts +1 -1
- package/dist/decorators/logMethod.decorator.js +3 -3
- package/dist/decorators/retry.decorator.d.ts +1 -1
- package/dist/decorators/retry.decorator.js +1 -1
- package/dist/error/tryCatch.d.ts +1 -1
- package/dist/error/tryCatch.js +1 -1
- package/dist/index.d.ts +1 -2
- package/dist/index.js +0 -2
- package/dist/json-schema/from-data/generateJsonSchemaFromData.js +1 -1
- package/dist/json-schema/jsonSchema.util.js +1 -1
- package/dist/json-schema/jsonSchemaBuilder.d.ts +1 -2
- package/dist/json-schema/jsonSchemaBuilder.js +3 -2
- package/dist/math/stack.util.js +1 -1
- package/dist/promise/pMap.d.ts +2 -2
- package/dist/promise/pMap.js +1 -1
- package/dist/promise/pRetry.d.ts +2 -2
- package/dist/promise/pRetry.js +2 -2
- package/dist/validation/validation.d.ts +30 -0
- package/dist/validation/validation.js +1 -0
- package/package.json +15 -6
- package/src/array/index.ts +2 -0
- package/src/browser/analytics.util.ts +1 -1
- package/src/decorators/logMethod.decorator.ts +4 -4
- package/src/decorators/retry.decorator.ts +2 -2
- package/src/error/tryCatch.ts +2 -2
- package/src/index.ts +1 -2
- package/src/json-schema/from-data/generateJsonSchemaFromData.ts +1 -1
- package/src/json-schema/jsonSchema.util.ts +1 -1
- package/src/json-schema/jsonSchemaBuilder.ts +7 -8
- package/src/math/stack.util.ts +1 -1
- package/src/promise/pMap.ts +2 -2
- package/src/promise/pRetry.ts +4 -3
- package/src/validation/validation.ts +35 -0
- package/dist/log/index.d.ts +0 -1
- package/dist/log/index.js +0 -1
- package/src/log/index.ts +0 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { _ms } from '../datetime/time.util.js';
|
|
2
|
-
import { _assert } from '../error/
|
|
3
|
-
import { SimpleMovingAverage } from '../math/
|
|
4
|
-
import { _stringify } from '../string/
|
|
2
|
+
import { _assert } from '../error/assert.js';
|
|
3
|
+
import { SimpleMovingAverage } from '../math/sma.js';
|
|
4
|
+
import { _stringify } from '../string/stringify.js';
|
|
5
5
|
import { _getArgsSignature, _getMethodSignature } from './decorator.util.js';
|
|
6
6
|
/**
|
|
7
7
|
* Console-logs when method had started, when it finished, time taken and if error happened.
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type { PRetryOptions } from '../promise/
|
|
1
|
+
import type { PRetryOptions } from '../promise/pRetry.js';
|
|
2
2
|
export declare function _Retry(opt?: PRetryOptions): MethodDecorator;
|
package/dist/error/tryCatch.d.ts
CHANGED
package/dist/error/tryCatch.js
CHANGED
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
export * from './abort.js';
|
|
2
|
-
export * from './array/array.util.js';
|
|
3
|
-
export * from './array/range.js';
|
|
4
2
|
export * from './bot.model.js';
|
|
5
3
|
export * from './define.js';
|
|
6
4
|
export * from './enum.util.js';
|
|
@@ -14,4 +12,5 @@ export * from './number/createDeterministicRandom.js';
|
|
|
14
12
|
export * from './number/number.util.js';
|
|
15
13
|
export * from './polyfill.js';
|
|
16
14
|
export * from './unit/size.util.js';
|
|
15
|
+
export type * from './validation/validation.js';
|
|
17
16
|
export * from './web.js';
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import type { AnyObject, BaseDBEntity } from '../types.js';
|
|
2
|
-
import {
|
|
3
|
-
import type { JsonSchema, JsonSchemaAny, JsonSchemaBoolean, JsonSchemaConst, JsonSchemaEnum, JsonSchemaNull, JsonSchemaNumber, JsonSchemaObject, JsonSchemaRef, JsonSchemaString } from './jsonSchema.model.js';
|
|
2
|
+
import type { JsonSchema, JsonSchemaAllOf, JsonSchemaAny, JsonSchemaArray, JsonSchemaBoolean, JsonSchemaConst, JsonSchemaEnum, JsonSchemaNull, JsonSchemaNumber, JsonSchemaObject, JsonSchemaOneOf, JsonSchemaRef, JsonSchemaString, JsonSchemaTuple } from './jsonSchema.model.js';
|
|
4
3
|
export interface JsonSchemaBuilder<T = unknown> {
|
|
5
4
|
build: () => JsonSchema<T>;
|
|
6
5
|
}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { _uniq } from '../array/array.util.js';
|
|
2
|
-
import { _deepCopy
|
|
3
|
-
import {
|
|
2
|
+
import { _deepCopy } from '../object/object.util.js';
|
|
3
|
+
import { _sortObject } from '../object/sortObject.js';
|
|
4
4
|
import { JSON_SCHEMA_ORDER } from './jsonSchema.cnst.js';
|
|
5
|
+
import { mergeJsonSchemaObjects } from './jsonSchema.util.js';
|
|
5
6
|
/**
|
|
6
7
|
* Fluent (chainable) API to manually create Json Schemas.
|
|
7
8
|
* Inspired by Joi
|
package/dist/math/stack.util.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { _range } from '../array/range.js';
|
|
2
|
-
import { _average, _percentile, _percentiles } from '
|
|
2
|
+
import { _average, _percentile, _percentiles } from './math.util.js';
|
|
3
3
|
/**
|
|
4
4
|
* Implements a "round-robin" Stack ("first-in last-out" aka FILO) with a limited size.
|
|
5
5
|
* Like an array of a fixed size. When it runs out of space - it starts writing on top of itself
|
package/dist/promise/pMap.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { ErrorMode } from '../error/
|
|
2
|
-
import type { CommonLogger } from '../log/
|
|
1
|
+
import { ErrorMode } from '../error/errorMode.js';
|
|
2
|
+
import type { CommonLogger } from '../log/commonLogger.js';
|
|
3
3
|
import { type AbortableAsyncMapper } from '../types.js';
|
|
4
4
|
export interface PMapOptions {
|
|
5
5
|
/**
|
package/dist/promise/pMap.js
CHANGED
package/dist/promise/pRetry.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import type { CommonLogger } from '../log/
|
|
1
|
+
import type { ErrorData } from '../error/error.model.js';
|
|
2
|
+
import type { CommonLogger } from '../log/commonLogger.js';
|
|
3
3
|
import type { AnyFunction } from '../types.js';
|
|
4
4
|
export interface PRetryOptions {
|
|
5
5
|
/**
|
package/dist/promise/pRetry.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { _since } from '../datetime/
|
|
2
|
-
import { _errorDataAppend } from '../error/
|
|
1
|
+
import { _since } from '../datetime/time.util.js';
|
|
2
|
+
import { _errorDataAppend } from '../error/error.util.js';
|
|
3
3
|
import { pDelay } from './pDelay.js';
|
|
4
4
|
import { pTimeout } from './pTimeout.js';
|
|
5
5
|
/**
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { AppError } from '../error/error.util.js';
|
|
2
|
+
import type { ErrorDataTuple } from '../types.js';
|
|
3
|
+
/**
|
|
4
|
+
* Item to be validated.
|
|
5
|
+
* Can be null or undefined, which allows validation function to produce an error,
|
|
6
|
+
* if undefined/null are not accepted. But they might be accepted too, it depends
|
|
7
|
+
* on the schema (implementation detail of the ValidationFunction).
|
|
8
|
+
*
|
|
9
|
+
* Function returns a tuple of [err, item].
|
|
10
|
+
* In case of error it will be [err, null].
|
|
11
|
+
* In case of success it is [null, item].
|
|
12
|
+
*
|
|
13
|
+
* ValidationFunction may mutate the input item or not,
|
|
14
|
+
* depending on the implementation.
|
|
15
|
+
*
|
|
16
|
+
* @experimental
|
|
17
|
+
*/
|
|
18
|
+
export type ValidationFunction<T, ERR extends AppError> = (item: T | null | undefined, opt?: ValidationFunctionOptions) => ErrorDataTuple<T, ERR>;
|
|
19
|
+
export interface ValidationFunctionOptions {
|
|
20
|
+
/**
|
|
21
|
+
* E.g User
|
|
22
|
+
* Used for error message printing.
|
|
23
|
+
*/
|
|
24
|
+
itemName?: string;
|
|
25
|
+
/**
|
|
26
|
+
* E.g `12345678` (user id).
|
|
27
|
+
* Used for error message printing.
|
|
28
|
+
*/
|
|
29
|
+
itemId?: string;
|
|
30
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,36 +1,46 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@naturalcycles/js-lib",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "15.
|
|
4
|
+
"version": "15.18.0",
|
|
5
5
|
"dependencies": {
|
|
6
6
|
"tslib": "^2",
|
|
7
7
|
"zod": "^4"
|
|
8
8
|
},
|
|
9
9
|
"devDependencies": {
|
|
10
|
-
"@naturalcycles/dev-lib": "*",
|
|
11
10
|
"@types/crypto-js": "^4",
|
|
12
11
|
"@types/node": "^24",
|
|
13
12
|
"@types/semver": "^7",
|
|
14
13
|
"crypto-js": "^4",
|
|
15
|
-
"dayjs": "^1"
|
|
14
|
+
"dayjs": "^1",
|
|
15
|
+
"@naturalcycles/dev-lib": "19.11.0"
|
|
16
16
|
},
|
|
17
17
|
"exports": {
|
|
18
|
-
"./cfg/frontend/tsconfig.json": "./cfg/frontend/tsconfig.json",
|
|
19
18
|
".": "./dist/index.js",
|
|
19
|
+
"./cfg/frontend/tsconfig.json": "./cfg/frontend/tsconfig.json",
|
|
20
|
+
"./array": "./dist/array/index.js",
|
|
21
|
+
"./array/*.js": "./dist/array/*.js",
|
|
20
22
|
"./browser": "./dist/browser/index.js",
|
|
23
|
+
"./browser/*.js": "./dist/browser/*.js",
|
|
21
24
|
"./datetime": "./dist/datetime/index.js",
|
|
25
|
+
"./datetime/*.js": "./dist/datetime/*.js",
|
|
22
26
|
"./decorators": "./dist/decorators/index.js",
|
|
27
|
+
"./decorators/*.js": "./dist/decorators/*.js",
|
|
23
28
|
"./deviceIdService": "./dist/deviceIdService.js",
|
|
24
29
|
"./error": "./dist/error/index.js",
|
|
30
|
+
"./error/*.js": "./dist/error/*.js",
|
|
25
31
|
"./http": "./dist/http/index.js",
|
|
26
32
|
"./json-schema": "./dist/json-schema/index.js",
|
|
27
|
-
"./log": "./dist/log/
|
|
33
|
+
"./log": "./dist/log/commonLogger.js",
|
|
28
34
|
"./math": "./dist/math/index.js",
|
|
35
|
+
"./math/*.js": "./dist/math/*.js",
|
|
29
36
|
"./object": "./dist/object/index.js",
|
|
37
|
+
"./object/*.js": "./dist/object/*.js",
|
|
30
38
|
"./promise": "./dist/promise/index.js",
|
|
39
|
+
"./promise/*.js": "./dist/promise/*.js",
|
|
31
40
|
"./nanoid": "./dist/nanoid.js",
|
|
32
41
|
"./semver": "./dist/semver.js",
|
|
33
42
|
"./string": "./dist/string/index.js",
|
|
43
|
+
"./string/*.js": "./dist/string/*.js",
|
|
34
44
|
"./types": "./dist/types.js",
|
|
35
45
|
"./zod": "./dist/zod/index.js"
|
|
36
46
|
},
|
|
@@ -42,7 +52,6 @@
|
|
|
42
52
|
"!src/**/*.test.*",
|
|
43
53
|
"!src/**/__snapshots__"
|
|
44
54
|
],
|
|
45
|
-
"main": "dist/index.js",
|
|
46
55
|
"types": "dist/index.d.ts",
|
|
47
56
|
"sideEffects": false,
|
|
48
57
|
"engines": {
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { _ms } from '../datetime/time.util.js'
|
|
2
|
-
import { _assert } from '../error/
|
|
3
|
-
import type { CommonLogger } from '../log/
|
|
4
|
-
import { SimpleMovingAverage } from '../math/
|
|
5
|
-
import { _stringify } from '../string/
|
|
2
|
+
import { _assert } from '../error/assert.js'
|
|
3
|
+
import type { CommonLogger } from '../log/commonLogger.js'
|
|
4
|
+
import { SimpleMovingAverage } from '../math/sma.js'
|
|
5
|
+
import { _stringify } from '../string/stringify.js'
|
|
6
6
|
import { _getArgsSignature, _getMethodSignature } from './decorator.util.js'
|
|
7
7
|
|
|
8
8
|
/**
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { PRetryOptions } from '../promise/
|
|
2
|
-
import { pRetryFn } from '../promise/
|
|
1
|
+
import type { PRetryOptions } from '../promise/pRetry.js'
|
|
2
|
+
import { pRetryFn } from '../promise/pRetry.js'
|
|
3
3
|
|
|
4
4
|
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
5
5
|
export function _Retry(opt: PRetryOptions = {}): MethodDecorator {
|
package/src/error/tryCatch.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { _since } from '../datetime/
|
|
2
|
-
import type { CommonLogger } from '../log/
|
|
1
|
+
import { _since } from '../datetime/time.util.js'
|
|
2
|
+
import type { CommonLogger } from '../log/commonLogger.js'
|
|
3
3
|
import type { AnyFunction, UnixTimestampMillis } from '../types.js'
|
|
4
4
|
import { _anyToError } from './error.util.js'
|
|
5
5
|
|
package/src/index.ts
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
export * from './abort.js'
|
|
2
|
-
export * from './array/array.util.js'
|
|
3
|
-
export * from './array/range.js'
|
|
4
2
|
export * from './bot.model.js'
|
|
5
3
|
export * from './define.js'
|
|
6
4
|
export * from './enum.util.js'
|
|
@@ -14,4 +12,5 @@ export * from './number/createDeterministicRandom.js'
|
|
|
14
12
|
export * from './number/number.util.js'
|
|
15
13
|
export * from './polyfill.js'
|
|
16
14
|
export * from './unit/size.util.js'
|
|
15
|
+
export type * from './validation/validation.js'
|
|
17
16
|
export * from './web.js'
|
|
@@ -1,26 +1,25 @@
|
|
|
1
1
|
import { _uniq } from '../array/array.util.js'
|
|
2
|
-
import { _deepCopy
|
|
2
|
+
import { _deepCopy } from '../object/object.util.js'
|
|
3
|
+
import { _sortObject } from '../object/sortObject.js'
|
|
3
4
|
import type { AnyObject, BaseDBEntity } from '../types.js'
|
|
4
|
-
import {
|
|
5
|
-
type JsonSchemaAllOf,
|
|
6
|
-
type JsonSchemaArray,
|
|
7
|
-
type JsonSchemaOneOf,
|
|
8
|
-
type JsonSchemaTuple,
|
|
9
|
-
mergeJsonSchemaObjects,
|
|
10
|
-
} from './index.js'
|
|
11
5
|
import { JSON_SCHEMA_ORDER } from './jsonSchema.cnst.js'
|
|
12
6
|
import type {
|
|
13
7
|
JsonSchema,
|
|
8
|
+
JsonSchemaAllOf,
|
|
14
9
|
JsonSchemaAny,
|
|
10
|
+
JsonSchemaArray,
|
|
15
11
|
JsonSchemaBoolean,
|
|
16
12
|
JsonSchemaConst,
|
|
17
13
|
JsonSchemaEnum,
|
|
18
14
|
JsonSchemaNull,
|
|
19
15
|
JsonSchemaNumber,
|
|
20
16
|
JsonSchemaObject,
|
|
17
|
+
JsonSchemaOneOf,
|
|
21
18
|
JsonSchemaRef,
|
|
22
19
|
JsonSchemaString,
|
|
20
|
+
JsonSchemaTuple,
|
|
23
21
|
} from './jsonSchema.model.js'
|
|
22
|
+
import { mergeJsonSchemaObjects } from './jsonSchema.util.js'
|
|
24
23
|
|
|
25
24
|
/* eslint-disable id-blacklist, @typescript-eslint/explicit-module-boundary-types */
|
|
26
25
|
|
package/src/math/stack.util.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { _range } from '../array/range.js'
|
|
2
|
-
import { _average, _percentile, _percentiles } from '
|
|
2
|
+
import { _average, _percentile, _percentiles } from './math.util.js'
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Implements a "round-robin" Stack ("first-in last-out" aka FILO) with a limited size.
|
package/src/promise/pMap.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { ErrorMode } from '../error/
|
|
2
|
-
import type { CommonLogger } from '../log/
|
|
1
|
+
import { ErrorMode } from '../error/errorMode.js'
|
|
2
|
+
import type { CommonLogger } from '../log/commonLogger.js'
|
|
3
3
|
import { type AbortableAsyncMapper, END, SKIP } from '../types.js'
|
|
4
4
|
|
|
5
5
|
export interface PMapOptions {
|
package/src/promise/pRetry.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { _since } from '../datetime/
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
1
|
+
import { _since } from '../datetime/time.util.js'
|
|
2
|
+
import type { ErrorData } from '../error/error.model.js'
|
|
3
|
+
import { _errorDataAppend } from '../error/error.util.js'
|
|
4
|
+
import type { CommonLogger } from '../log/commonLogger.js'
|
|
4
5
|
import type { AnyFunction, UnixTimestampMillis } from '../types.js'
|
|
5
6
|
import { pDelay } from './pDelay.js'
|
|
6
7
|
import { pTimeout } from './pTimeout.js'
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { AppError } from '../error/error.util.js'
|
|
2
|
+
import type { ErrorDataTuple } from '../types.js'
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Item to be validated.
|
|
6
|
+
* Can be null or undefined, which allows validation function to produce an error,
|
|
7
|
+
* if undefined/null are not accepted. But they might be accepted too, it depends
|
|
8
|
+
* on the schema (implementation detail of the ValidationFunction).
|
|
9
|
+
*
|
|
10
|
+
* Function returns a tuple of [err, item].
|
|
11
|
+
* In case of error it will be [err, null].
|
|
12
|
+
* In case of success it is [null, item].
|
|
13
|
+
*
|
|
14
|
+
* ValidationFunction may mutate the input item or not,
|
|
15
|
+
* depending on the implementation.
|
|
16
|
+
*
|
|
17
|
+
* @experimental
|
|
18
|
+
*/
|
|
19
|
+
export type ValidationFunction<T, ERR extends AppError> = (
|
|
20
|
+
item: T | null | undefined,
|
|
21
|
+
opt?: ValidationFunctionOptions,
|
|
22
|
+
) => ErrorDataTuple<T, ERR>
|
|
23
|
+
|
|
24
|
+
export interface ValidationFunctionOptions {
|
|
25
|
+
/**
|
|
26
|
+
* E.g User
|
|
27
|
+
* Used for error message printing.
|
|
28
|
+
*/
|
|
29
|
+
itemName?: string
|
|
30
|
+
/**
|
|
31
|
+
* E.g `12345678` (user id).
|
|
32
|
+
* Used for error message printing.
|
|
33
|
+
*/
|
|
34
|
+
itemId?: string
|
|
35
|
+
}
|
package/dist/log/index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './commonLogger.js';
|
package/dist/log/index.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './commonLogger.js';
|
package/src/log/index.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './commonLogger.js'
|