@naturalcycles/nodejs-lib 15.133.0 → 15.134.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.
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { ValidationFunction, ValidationFunctionResult } from '@naturalcycles/js-lib';
|
|
2
2
|
import type { Set2 } from '@naturalcycles/js-lib/object';
|
|
3
|
-
import type { AnyObject, BaseDBEntity, IANATimezone, Inclusiveness, IsoDate, IsoDateTime, IsoMonth, Enum, NumberEnum, StringEnum, StringMap, UnixTimestamp, UnixTimestampMillis } from '@naturalcycles/js-lib/types';
|
|
3
|
+
import type { AnyObject, BaseDBEntity, IANATimezone, Inclusiveness, IsoDate, IsoDateTime, IsoMonth, Enum, NonEmptyArray, NumberEnum, StringEnum, StringMap, UnixTimestamp, UnixTimestampMillis } from '@naturalcycles/js-lib/types';
|
|
4
4
|
import type { StandardJSONSchemaV1, StandardSchemaV1 } from '@standard-schema/spec';
|
|
5
5
|
import type { Ajv, ValidateFunction } from 'ajv';
|
|
6
6
|
import { AjvValidationError } from './ajvValidationError.js';
|
|
@@ -408,13 +408,17 @@ export declare class JObjectInfer<PROPS extends Record<string, JSchema<any, any>
|
|
|
408
408
|
updated: JNumber<UnixTimestamp, false>;
|
|
409
409
|
}[K] : K extends keyof PROPS ? PROPS[K] : never; }, Opt>;
|
|
410
410
|
}
|
|
411
|
-
export declare class JArray<OUT, Opt> extends JBuilder<
|
|
411
|
+
export declare class JArray<OUT, Opt, ARR extends OUT[] = OUT[]> extends JBuilder<ARR, Opt> {
|
|
412
412
|
constructor(itemsSchema: JSchema<OUT, Opt>);
|
|
413
413
|
minLength(minItems: number): this;
|
|
414
414
|
maxLength(maxItems: number): this;
|
|
415
415
|
length(exactLength: number): this;
|
|
416
416
|
length(minItems: number, maxItems: number): this;
|
|
417
417
|
exactLength(length: number): this;
|
|
418
|
+
/**
|
|
419
|
+
* Same as `minLength(1)`, but also narrows the output type to `NonEmptyArray`.
|
|
420
|
+
*/
|
|
421
|
+
nonEmpty(): JArray<OUT, Opt, NonEmptyArray<OUT>>;
|
|
418
422
|
unique(): this;
|
|
419
423
|
}
|
|
420
424
|
declare class JSet2Builder<OUT, Opt> extends JBuilder<Set2<OUT>, Opt> {
|
|
@@ -942,6 +942,12 @@ export class JArray extends JBuilder {
|
|
|
942
942
|
exactLength(length) {
|
|
943
943
|
return this.minLength(length).maxLength(length);
|
|
944
944
|
}
|
|
945
|
+
/**
|
|
946
|
+
* Same as `minLength(1)`, but also narrows the output type to `NonEmptyArray`.
|
|
947
|
+
*/
|
|
948
|
+
nonEmpty() {
|
|
949
|
+
return this.minLength(1);
|
|
950
|
+
}
|
|
945
951
|
unique() {
|
|
946
952
|
return this.cloneAndUpdateSchema({ uniqueItems: true });
|
|
947
953
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@naturalcycles/nodejs-lib",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "15.
|
|
4
|
+
"version": "15.134.0",
|
|
5
5
|
"dependencies": {
|
|
6
6
|
"@naturalcycles/js-lib": "^15",
|
|
7
7
|
"@standard-schema/spec": "^1",
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
"yaml": "^2"
|
|
15
15
|
},
|
|
16
16
|
"devDependencies": {
|
|
17
|
-
"@naturalcycles/dev-lib": "
|
|
17
|
+
"@naturalcycles/dev-lib": "0.0.0",
|
|
18
18
|
"typescript": "^7"
|
|
19
19
|
},
|
|
20
20
|
"exports": {
|
|
@@ -20,6 +20,7 @@ import type {
|
|
|
20
20
|
IsoDateTime,
|
|
21
21
|
IsoMonth,
|
|
22
22
|
Enum,
|
|
23
|
+
NonEmptyArray,
|
|
23
24
|
NumberEnum,
|
|
24
25
|
StringEnum,
|
|
25
26
|
StringMap,
|
|
@@ -1290,7 +1291,7 @@ export class JObjectInfer<
|
|
|
1290
1291
|
}
|
|
1291
1292
|
}
|
|
1292
1293
|
|
|
1293
|
-
export class JArray<OUT, Opt> extends JBuilder<
|
|
1294
|
+
export class JArray<OUT, Opt, ARR extends OUT[] = OUT[]> extends JBuilder<ARR, Opt> {
|
|
1294
1295
|
constructor(itemsSchema: JSchema<OUT, Opt>) {
|
|
1295
1296
|
super({
|
|
1296
1297
|
type: 'array',
|
|
@@ -1317,6 +1318,13 @@ export class JArray<OUT, Opt> extends JBuilder<OUT[], Opt> {
|
|
|
1317
1318
|
return this.minLength(length).maxLength(length)
|
|
1318
1319
|
}
|
|
1319
1320
|
|
|
1321
|
+
/**
|
|
1322
|
+
* Same as `minLength(1)`, but also narrows the output type to `NonEmptyArray`.
|
|
1323
|
+
*/
|
|
1324
|
+
nonEmpty(): JArray<OUT, Opt, NonEmptyArray<OUT>> {
|
|
1325
|
+
return this.minLength(1) as any as JArray<OUT, Opt, NonEmptyArray<OUT>>
|
|
1326
|
+
}
|
|
1327
|
+
|
|
1320
1328
|
unique(): this {
|
|
1321
1329
|
return this.cloneAndUpdateSchema({ uniqueItems: true })
|
|
1322
1330
|
}
|