@naturalcycles/nodejs-lib 13.36.0 → 13.37.1

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,4 +1,4 @@
1
- import { BaseDBEntity, NumberEnum, StringEnum, UnixTimestamp, UnixTimestampMillis } from '@naturalcycles/js-lib';
1
+ import { BaseDBEntity, IsoDateTime, NumberEnum, StringEnum, UnixTimestamp, UnixTimestampMillis } from '@naturalcycles/js-lib';
2
2
  import { AlternativesSchema, AnySchema, ArraySchema, ObjectSchema } from 'joi';
3
3
  import { NumberSchema } from './number.extensions';
4
4
  import { StringSchema } from './string.extensions';
@@ -10,12 +10,12 @@ export declare const numberSchema: NumberSchema<number>;
10
10
  export declare const numberSchemaTyped: <T>() => NumberSchema<T>;
11
11
  export declare const integerSchema: NumberSchema<number>;
12
12
  export declare const percentageSchema: NumberSchema<number>;
13
- export declare const dateStringSchema: StringSchema<string>;
13
+ export declare const dateStringSchema: StringSchema<import("@naturalcycles/js-lib").IsoDate>;
14
14
  export declare const binarySchema: import("joi").BinarySchema<Buffer>;
15
15
  export declare const dateObjectSchema: ObjectSchema<any>;
16
16
  export declare const dateIntervalStringSchema: StringSchema<string>;
17
17
  export declare const DATE_TIME_STRING_REGEX: RegExp;
18
- export declare const dateTimeStringSchema: StringSchema<string>;
18
+ export declare const dateTimeStringSchema: StringSchema<IsoDateTime>;
19
19
  /**
20
20
  * Allows all values of a String Enum.
21
21
  */
@@ -1,10 +1,11 @@
1
+ import { IsoDate } from '@naturalcycles/js-lib';
1
2
  import type Joi from 'joi';
2
3
  import { Extension, StringSchema as JoiStringSchema } from 'joi';
3
4
  export interface StringSchema<TSchema = string> extends JoiStringSchema<TSchema> {
4
- dateString: (min?: string, max?: string) => this;
5
+ dateString: (min?: IsoDate | 'today', max?: IsoDate | 'today') => StringSchema<IsoDate>;
5
6
  }
6
7
  export interface JoiDateStringOptions {
7
- min?: string;
8
- max?: string;
8
+ min?: IsoDate | 'today';
9
+ max?: IsoDate | 'today';
9
10
  }
10
11
  export declare function stringExtensions(joi: typeof Joi): Extension;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@naturalcycles/nodejs-lib",
3
- "version": "13.36.0",
3
+ "version": "13.37.1",
4
4
  "scripts": {
5
5
  "prepare": "husky",
6
6
  "build": "dev-lib build",
@@ -4,6 +4,7 @@ import {
4
4
  _stringEnumKeys,
5
5
  _stringEnumValues,
6
6
  BaseDBEntity,
7
+ IsoDateTime,
7
8
  NumberEnum,
8
9
  StringEnum,
9
10
  UnixTimestamp,
@@ -36,7 +37,7 @@ export const DATE_TIME_STRING_REGEX =
36
37
 
37
38
  export const dateTimeStringSchema = stringSchema.regex(DATE_TIME_STRING_REGEX).messages({
38
39
  'string.pattern.base': `must be a DateTime string`,
39
- })
40
+ }) as StringSchema<IsoDateTime>
40
41
 
41
42
  /**
42
43
  * Allows all values of a String Enum.
@@ -1,14 +1,14 @@
1
- import { localTime } from '@naturalcycles/js-lib'
1
+ import { IsoDate, localTime } from '@naturalcycles/js-lib'
2
2
  import type Joi from 'joi'
3
3
  import { Extension, StringSchema as JoiStringSchema } from 'joi'
4
4
 
5
5
  export interface StringSchema<TSchema = string> extends JoiStringSchema<TSchema> {
6
- dateString: (min?: string, max?: string) => this
6
+ dateString: (min?: IsoDate | 'today', max?: IsoDate | 'today') => StringSchema<IsoDate>
7
7
  }
8
8
 
9
9
  export interface JoiDateStringOptions {
10
- min?: string
11
- max?: string
10
+ min?: IsoDate | 'today'
11
+ max?: IsoDate | 'today'
12
12
  }
13
13
 
14
14
  export function stringExtensions(joi: typeof Joi): Extension {
@@ -24,7 +24,7 @@ export function stringExtensions(joi: typeof Joi): Extension {
24
24
  },
25
25
  rules: {
26
26
  dateString: {
27
- method(min?: string, max?: string) {
27
+ method(min?: IsoDate, max?: IsoDate) {
28
28
  return this.$_addRule({
29
29
  name: 'dateString',
30
30
  args: { min, max } satisfies JoiDateStringOptions,
@@ -101,11 +101,11 @@ function isLeapYear(year: number): boolean {
101
101
  }
102
102
 
103
103
  let lastCheckedPlus = 0
104
- let todayStrPlusCached: string
104
+ let todayStrPlusCached: IsoDate
105
105
  let lastCheckedMinus = 0
106
- let todayStrMinusCached: string
106
+ let todayStrMinusCached: IsoDate
107
107
 
108
- function getTodayStrPlus15(): string {
108
+ function getTodayStrPlus15(): IsoDate {
109
109
  const now = Date.now()
110
110
  if (now - lastCheckedPlus < 3_600_000) {
111
111
  // cached for 1 hour
@@ -116,7 +116,7 @@ function getTodayStrPlus15(): string {
116
116
  return (todayStrPlusCached = localTime.now().plus(15, 'hour').toISODate())
117
117
  }
118
118
 
119
- function getTodayStrMinus15(): string {
119
+ function getTodayStrMinus15(): IsoDate {
120
120
  const now = Date.now()
121
121
  if (now - lastCheckedMinus < 3_600_000) {
122
122
  // cached for 1 hour