@naturalcycles/nodejs-lib 15.122.3 → 15.123.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, NumberEnum, StringEnum, StringMap, UnixTimestamp, UnixTimestampMillis } from '@naturalcycles/js-lib/types';
3
+ import type { AnyObject, BaseDBEntity, IANATimezone, Inclusiveness, IsoDate, IsoDateTime, IsoMonth, Enum, 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';
@@ -66,7 +66,9 @@ export declare const j: {
66
66
  tuple<const S extends JSchema<any, any>[]>(items: S): JTuple<S>;
67
67
  set<OUT, Opt>(itemSchema: JSchema<OUT, Opt>): JSet2Builder<OUT, Opt>;
68
68
  buffer(): JBuilder<Buffer, false>;
69
- enum<const T extends readonly (string | number | boolean | null)[] | StringEnum | NumberEnum>(input: T, opt?: JsonBuilderRuleOpt): JEnum<T extends readonly (infer U)[] ? U : T extends StringEnum ? T[keyof T] : T extends NumberEnum ? T[keyof T] : never>;
69
+ enum<const T extends readonly (string | number | boolean | null)[] | StringEnum | NumberEnum | {
70
+ readonly values: readonly (string | number | boolean | null)[];
71
+ }>(input: T, opt?: JsonBuilderRuleOpt): JEnum<T extends readonly (infer U)[] ? U : Enum<T>>;
70
72
  /**
71
73
  * Use only with primitive values, otherwise this function will throw to avoid bugs.
72
74
  * To validate objects, use `anyOfBy`.
@@ -771,13 +771,13 @@ export class JNumber extends JBuilder {
771
771
  return this;
772
772
  }
773
773
  unixTimestamp() {
774
- return this.integer().min(0).max(TS_2500).branded();
774
+ return this.integer().branded();
775
775
  }
776
776
  unixTimestamp2000() {
777
777
  return this.integer().min(TS_2000).max(TS_2500).branded();
778
778
  }
779
779
  unixTimestampMillis() {
780
- return this.integer().min(0).max(TS_2500_MILLIS).branded();
780
+ return this.integer().branded();
781
781
  }
782
782
  unixTimestamp2000Millis() {
783
783
  return this.integer().min(TS_2000_MILLIS).max(TS_2500_MILLIS).branded();
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@naturalcycles/nodejs-lib",
3
3
  "type": "module",
4
- "version": "15.122.3",
4
+ "version": "15.123.0",
5
5
  "dependencies": {
6
6
  "@naturalcycles/js-lib": "^15",
7
7
  "@standard-schema/spec": "^1",
@@ -19,6 +19,7 @@ import type {
19
19
  IsoDate,
20
20
  IsoDateTime,
21
21
  IsoMonth,
22
+ Enum,
22
23
  NumberEnum,
23
24
  StringEnum,
24
25
  StringMap,
@@ -172,18 +173,14 @@ export const j = {
172
173
  })
173
174
  },
174
175
 
175
- enum<const T extends readonly (string | number | boolean | null)[] | StringEnum | NumberEnum>(
176
- input: T,
177
- opt?: JsonBuilderRuleOpt,
178
- ): JEnum<
179
- T extends readonly (infer U)[]
180
- ? U
181
- : T extends StringEnum
182
- ? T[keyof T]
183
- : T extends NumberEnum
184
- ? T[keyof T]
185
- : never
186
- > {
176
+ enum<
177
+ const T extends
178
+ | readonly (string | number | boolean | null)[]
179
+ | StringEnum
180
+ | NumberEnum
181
+ // an `_enum()` object, which carries helpers and so satisfies neither of the two above
182
+ | { readonly values: readonly (string | number | boolean | null)[] },
183
+ >(input: T, opt?: JsonBuilderRuleOpt): JEnum<T extends readonly (infer U)[] ? U : Enum<T>> {
187
184
  let enumValues: readonly (string | number | boolean | null)[] | undefined
188
185
  let baseType: EnumBaseType = 'other'
189
186
 
@@ -1030,7 +1027,7 @@ export class JNumber<
1030
1027
  }
1031
1028
 
1032
1029
  unixTimestamp(): JNumber<UnixTimestamp, Opt> {
1033
- return this.integer().min(0).max(TS_2500).branded<UnixTimestamp>()
1030
+ return this.integer().branded<UnixTimestamp>()
1034
1031
  }
1035
1032
 
1036
1033
  unixTimestamp2000(): JNumber<UnixTimestamp, Opt> {
@@ -1038,7 +1035,7 @@ export class JNumber<
1038
1035
  }
1039
1036
 
1040
1037
  unixTimestampMillis(): JNumber<UnixTimestampMillis, Opt> {
1041
- return this.integer().min(0).max(TS_2500_MILLIS).branded<UnixTimestampMillis>()
1038
+ return this.integer().branded<UnixTimestampMillis>()
1042
1039
  }
1043
1040
 
1044
1041
  unixTimestamp2000Millis(): JNumber<UnixTimestampMillis, Opt> {