@naturalcycles/nodejs-lib 13.34.6 → 13.36.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.
@@ -20,7 +20,7 @@ const buildInfo_util_1 = require("../util/buildInfo.util");
20
20
  },
21
21
  }).argv;
22
22
  const buildInfo = (0, buildInfo_util_1.generateBuildInfo)({
23
- overrideTimestamp,
23
+ overrideTimestamp: overrideTimestamp,
24
24
  });
25
25
  console.log(buildInfo);
26
26
  if (dir)
package/dist/fs/del.js CHANGED
@@ -56,7 +56,7 @@ async function del(_opt) {
56
56
  const dirnamesSorted = dirnames.sort().reverse();
57
57
  // console.log({ dirnamesSorted })
58
58
  const deletedDirs = [];
59
- for await (const dirpath of dirnamesSorted) {
59
+ for (const dirpath of dirnamesSorted) {
60
60
  if (await isEmptyDir(dirpath)) {
61
61
  // console.log(`empty dir: ${dirpath}`)
62
62
  await index_1.fs2.removePathAsync(dirpath);
@@ -1,4 +1,4 @@
1
- import { AbortableAsyncMapper, AsyncPredicate, CommonLogger, END, ErrorMode, Promisable, SKIP, StringMap, UnixTimestampMillisNumber } from '@naturalcycles/js-lib';
1
+ import { AbortableAsyncMapper, AsyncPredicate, CommonLogger, END, ErrorMode, Promisable, SKIP, StringMap, UnixTimestampMillis } from '@naturalcycles/js-lib';
2
2
  import { TransformTyped } from '../stream.model';
3
3
  export interface TransformMapOptions<IN = any, OUT = IN> {
4
4
  /**
@@ -66,7 +66,7 @@ export interface TransformMapStats {
66
66
  countErrors: number;
67
67
  countIn: number;
68
68
  countOut: number;
69
- started: UnixTimestampMillisNumber;
69
+ started: UnixTimestampMillis;
70
70
  }
71
71
  export interface TransformMapStatsSummary extends TransformMapStats {
72
72
  /**
@@ -1,8 +1,8 @@
1
- import { BuildInfo, UnixTimestampNumber } from '@naturalcycles/js-lib';
1
+ import { BuildInfo, UnixTimestamp } from '@naturalcycles/js-lib';
2
2
  export interface GenerateBuildInfoOptions {
3
3
  /**
4
4
  * If set - this timestamp will be used, instead of "current time".
5
5
  */
6
- overrideTimestamp?: UnixTimestampNumber;
6
+ overrideTimestamp?: UnixTimestamp;
7
7
  }
8
8
  export declare function generateBuildInfo(opt?: GenerateBuildInfoOptions): BuildInfo;
@@ -1,4 +1,4 @@
1
- import type { UnixTimestampNumber } from '@naturalcycles/js-lib';
1
+ import type { UnixTimestamp } from '@naturalcycles/js-lib';
2
2
  /**
3
3
  * Set of utility functions to work with git.
4
4
  */
@@ -17,7 +17,7 @@ declare class Git2 {
17
17
  pull(): void;
18
18
  push(): void;
19
19
  getCurrentCommitSha(full?: boolean): string;
20
- getCurrentCommitTimestamp(): UnixTimestampNumber;
20
+ getCurrentCommitTimestamp(): UnixTimestamp;
21
21
  getCurrentBranchName(): string;
22
22
  getCurrentRepoName(): string;
23
23
  }
@@ -1,4 +1,4 @@
1
- import { BaseDBEntity, NumberEnum, StringEnum } from '@naturalcycles/js-lib';
1
+ import { BaseDBEntity, 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';
@@ -14,6 +14,8 @@ export declare const dateStringSchema: StringSchema<string>;
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
+ export declare const DATE_TIME_STRING_REGEX: RegExp;
18
+ export declare const dateTimeStringSchema: StringSchema<string>;
17
19
  /**
18
20
  * Allows all values of a String Enum.
19
21
  */
@@ -65,19 +67,19 @@ export declare const slugSchema: StringSchema<string>;
65
67
  /**
66
68
  * Between years 1970 and 2050
67
69
  */
68
- export declare const unixTimestampSchema: NumberSchema<number>;
70
+ export declare const unixTimestampSchema: NumberSchema<UnixTimestamp>;
69
71
  /**
70
72
  * Between years 2000 and 2050
71
73
  */
72
- export declare const unixTimestamp2000Schema: NumberSchema<number>;
74
+ export declare const unixTimestamp2000Schema: NumberSchema<UnixTimestamp>;
73
75
  /**
74
76
  * Between years 1970 and 2050
75
77
  */
76
- export declare const unixTimestampMillisSchema: NumberSchema<number>;
78
+ export declare const unixTimestampMillisSchema: NumberSchema<UnixTimestampMillis>;
77
79
  /**
78
80
  * Between years 2000 and 2050
79
81
  */
80
- export declare const unixTimestampMillis2000Schema: NumberSchema<number>;
82
+ export declare const unixTimestampMillis2000Schema: NumberSchema<UnixTimestampMillis>;
81
83
  export declare const verSchema: NumberSchema<number>;
82
84
  /**
83
85
  * Be careful, by default emailSchema does TLD validation. To disable it - use `stringSchema.email({tld: false}).lowercase()`
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.uuidSchema = exports.macAddressSchema = exports.baseDBEntitySchema = exports.ipAddressSchema = exports.ianaTimezoneSchema = exports.utcOffsetSchema = exports.userAgentSchema = exports.semVerSchema = exports.SEM_VER_REGEX = exports.emailSchema = exports.verSchema = exports.unixTimestampMillis2000Schema = exports.unixTimestampMillisSchema = exports.unixTimestamp2000Schema = exports.unixTimestampSchema = exports.slugSchema = exports.SLUG_REGEX = exports.idBase64UrlSchema = exports.idBase64Schema = exports.idBase62Schema = exports.idSchema = exports.jwtSchema = exports.JWT_REGEX = exports.base64UrlSchema = exports.base64Schema = exports.base62Schema = exports.BASE64URL_REGEX = exports.BASE64_REGEX = exports.BASE62_REGEX = exports.anyObjectSchema = exports.anySchema = exports.urlSchema = exports.numberEnumKeySchema = exports.numberEnumValueSchema = exports.stringEnumKeySchema = exports.stringEnumValueSchema = exports.dateIntervalStringSchema = exports.dateObjectSchema = exports.binarySchema = exports.dateStringSchema = exports.percentageSchema = exports.integerSchema = exports.numberSchemaTyped = exports.numberSchema = exports.stringSchemaTyped = exports.stringSchema = exports.booleanDefaultToFalseSchema = exports.booleanSchema = void 0;
3
+ exports.uuidSchema = exports.macAddressSchema = exports.baseDBEntitySchema = exports.ipAddressSchema = exports.ianaTimezoneSchema = exports.utcOffsetSchema = exports.userAgentSchema = exports.semVerSchema = exports.SEM_VER_REGEX = exports.emailSchema = exports.verSchema = exports.unixTimestampMillis2000Schema = exports.unixTimestampMillisSchema = exports.unixTimestamp2000Schema = exports.unixTimestampSchema = exports.slugSchema = exports.SLUG_REGEX = exports.idBase64UrlSchema = exports.idBase64Schema = exports.idBase62Schema = exports.idSchema = exports.jwtSchema = exports.JWT_REGEX = exports.base64UrlSchema = exports.base64Schema = exports.base62Schema = exports.BASE64URL_REGEX = exports.BASE64_REGEX = exports.BASE62_REGEX = exports.anyObjectSchema = exports.anySchema = exports.urlSchema = exports.numberEnumKeySchema = exports.numberEnumValueSchema = exports.stringEnumKeySchema = exports.stringEnumValueSchema = exports.dateTimeStringSchema = exports.DATE_TIME_STRING_REGEX = exports.dateIntervalStringSchema = exports.dateObjectSchema = exports.binarySchema = exports.dateStringSchema = exports.percentageSchema = exports.integerSchema = exports.numberSchemaTyped = exports.numberSchema = exports.stringSchemaTyped = exports.stringSchema = exports.booleanDefaultToFalseSchema = exports.booleanSchema = void 0;
4
4
  exports.arraySchema = arraySchema;
5
5
  exports.objectSchema = objectSchema;
6
6
  exports.oneOfSchema = oneOfSchema;
@@ -23,6 +23,10 @@ const DATE_INTERVAL_REGEX = /^\d{4}-\d{2}-\d{2}\/\d{4}-\d{2}-\d{2}$/;
23
23
  exports.dateIntervalStringSchema = exports.stringSchema.regex(DATE_INTERVAL_REGEX).messages({
24
24
  'string.pattern.base': `must be a DateInterval string`,
25
25
  });
26
+ exports.DATE_TIME_STRING_REGEX = /^\d{4}-\d{2}-\d{2}(?:T\d{2}:\d{2}:\d{2}(?:\.\d{1,3})?(?:Z|[+-]\d{2}:\d{2})?)?$/;
27
+ exports.dateTimeStringSchema = exports.stringSchema.regex(exports.DATE_TIME_STRING_REGEX).messages({
28
+ 'string.pattern.base': `must be a DateTime string`,
29
+ });
26
30
  /**
27
31
  * Allows all values of a String Enum.
28
32
  */
@@ -86,11 +90,17 @@ const TS_2000 = 946684800; // 2000-01-01
86
90
  /**
87
91
  * Between years 1970 and 2050
88
92
  */
89
- exports.unixTimestampSchema = exports.numberSchema.integer().min(0).max(TS_2500);
93
+ exports.unixTimestampSchema = exports.numberSchema
94
+ .integer()
95
+ .min(0)
96
+ .max(TS_2500);
90
97
  /**
91
98
  * Between years 2000 and 2050
92
99
  */
93
- exports.unixTimestamp2000Schema = exports.numberSchema.integer().min(TS_2000).max(TS_2500);
100
+ exports.unixTimestamp2000Schema = exports.numberSchema
101
+ .integer()
102
+ .min(TS_2000)
103
+ .max(TS_2500);
94
104
  /**
95
105
  * Between years 1970 and 2050
96
106
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@naturalcycles/nodejs-lib",
3
- "version": "13.34.6",
3
+ "version": "13.36.0",
4
4
  "scripts": {
5
5
  "prepare": "husky",
6
6
  "build": "dev-lib build",
@@ -39,7 +39,6 @@
39
39
  "yargs": "^17.0.0"
40
40
  },
41
41
  "devDependencies": {
42
- "@biomejs/biome": "^1.8.3",
43
42
  "@naturalcycles/bench-lib": "^3.0.0",
44
43
  "@naturalcycles/dev-lib": "^15.0.3",
45
44
  "@types/node": "^22.1.0",
@@ -74,7 +73,7 @@
74
73
  "url": "https://github.com/NaturalCycles/nodejs-lib"
75
74
  },
76
75
  "engines": {
77
- "node": ">=20.12.0"
76
+ "node": ">=20.13.0"
78
77
  },
79
78
  "description": "Standard library for Node.js",
80
79
  "author": "Natural Cycles Team",
@@ -2,6 +2,7 @@
2
2
 
3
3
  import fs from 'node:fs'
4
4
  import path from 'node:path'
5
+ import { UnixTimestamp } from '@naturalcycles/js-lib'
5
6
  import yargs from 'yargs'
6
7
  import { appendToBashEnv, appendToGithubEnv, appendToGithubOutput } from '../fs/json2env'
7
8
  import { runScript } from '../script/runScript'
@@ -20,7 +21,7 @@ runScript(async () => {
20
21
  }).argv
21
22
 
22
23
  const buildInfo = generateBuildInfo({
23
- overrideTimestamp,
24
+ overrideTimestamp: overrideTimestamp as UnixTimestamp,
24
25
  })
25
26
  console.log(buildInfo)
26
27
 
package/src/fs/del.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { _since, pFilter, pMap } from '@naturalcycles/js-lib'
1
+ import { _since, pFilter, pMap, UnixTimestampMillis } from '@naturalcycles/js-lib'
2
2
  import { dimGrey, yellow } from '../colors/colors'
3
3
  import { fs2, globby } from '../index'
4
4
 
@@ -35,7 +35,7 @@ const DEF_OPT: DelOptions = {
35
35
  * @experimental
36
36
  */
37
37
  export async function del(_opt: DelOptions | DelSingleOption): Promise<void> {
38
- const started = Date.now()
38
+ const started = Date.now() as UnixTimestampMillis
39
39
 
40
40
  // Convert DelSingleOption to DelOptions
41
41
  if (typeof _opt === 'string') {
@@ -90,7 +90,7 @@ export async function del(_opt: DelOptions | DelSingleOption): Promise<void> {
90
90
  // console.log({ dirnamesSorted })
91
91
 
92
92
  const deletedDirs: string[] = []
93
- for await (const dirpath of dirnamesSorted) {
93
+ for (const dirpath of dirnamesSorted) {
94
94
  if (await isEmptyDir(dirpath)) {
95
95
  // console.log(`empty dir: ${dirpath}`)
96
96
  await fs2.removePathAsync(dirpath)
@@ -110,7 +110,7 @@ export async function del(_opt: DelOptions | DelSingleOption): Promise<void> {
110
110
  }
111
111
 
112
112
  export function delSync(_opt: DelOptions | DelSingleOption): void {
113
- const started = Date.now()
113
+ const started = Date.now() as UnixTimestampMillis
114
114
 
115
115
  // Convert DelSingleOption to DelOptions
116
116
  if (typeof _opt === 'string') {
package/src/fs/kpy.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import path from 'node:path'
2
- import { _since } from '@naturalcycles/js-lib'
2
+ import { _since, UnixTimestampMillis } from '@naturalcycles/js-lib'
3
3
  import { boldWhite, dimGrey, grey, yellow } from '../colors/colors'
4
4
  import { fs2, globby } from '../index'
5
5
 
@@ -43,7 +43,7 @@ export interface KpyOptions {
43
43
  }
44
44
 
45
45
  export async function kpy(opt: KpyOptions): Promise<void> {
46
- const started = Date.now()
46
+ const started = Date.now() as UnixTimestampMillis
47
47
 
48
48
  kpyPrepare(opt)
49
49
 
@@ -82,7 +82,7 @@ export async function kpy(opt: KpyOptions): Promise<void> {
82
82
  }
83
83
 
84
84
  export function kpySync(opt: KpyOptions): void {
85
- const started = Date.now()
85
+ const started = Date.now() as UnixTimestampMillis
86
86
 
87
87
  kpyPrepare(opt)
88
88
 
@@ -143,7 +143,7 @@ function kpyLogFilenames(opt: KpyOptions, filenames: string[]): void {
143
143
  )
144
144
  }
145
145
 
146
- function kpyLogResult(opt: KpyOptions, filenames: string[], started: number): void {
146
+ function kpyLogResult(opt: KpyOptions, filenames: string[], started: UnixTimestampMillis): void {
147
147
  if (opt.silent || filenames.length === 0) return
148
148
 
149
149
  console.log(
@@ -22,6 +22,7 @@ export class NDJsonStats {
22
22
  get rpsTotal(): number {
23
23
  return Math.round(this.rows / ((this.tookMillis || 1) / 1000))
24
24
  }
25
+
25
26
  get bpsTotal(): number {
26
27
  return this.sizeBytes === 0 ? 0 : Math.round(this.sizeBytes / ((this.tookMillis || 1) / 1000))
27
28
  }
@@ -6,7 +6,7 @@ import {
6
6
  CommonLogger,
7
7
  localTime,
8
8
  SimpleMovingAverage,
9
- UnixTimestampMillisNumber,
9
+ UnixTimestampMillis,
10
10
  } from '@naturalcycles/js-lib'
11
11
  import { boldWhite, dimGrey, hasColors, white, yellow } from '../colors/colors'
12
12
  import { SizeStack } from './sizeStack'
@@ -185,8 +185,8 @@ export class ProgressLogger<T> implements Disposable {
185
185
  logger: CommonLogger
186
186
  }
187
187
 
188
- private started!: UnixTimestampMillisNumber
189
- private lastSecondStarted!: UnixTimestampMillisNumber
188
+ private started!: UnixTimestampMillis
189
+ private lastSecondStarted!: UnixTimestampMillis
190
190
  private sma!: SimpleMovingAverage
191
191
  private logEvery10!: number
192
192
  private processedLastSecond!: number
@@ -196,8 +196,8 @@ export class ProgressLogger<T> implements Disposable {
196
196
  private sizesZipped?: SizeStack
197
197
 
198
198
  private start(): void {
199
- this.started = Date.now()
200
- this.lastSecondStarted = Date.now()
199
+ this.started = Date.now() as UnixTimestampMillis
200
+ this.lastSecondStarted = Date.now() as UnixTimestampMillis
201
201
  this.sma = new SimpleMovingAverage(10)
202
202
  this.processedLastSecond = 0
203
203
  this.progress = 0
@@ -250,7 +250,7 @@ export class ProgressLogger<T> implements Disposable {
250
250
 
251
251
  const mem = process.memoryUsage()
252
252
 
253
- const now = Date.now()
253
+ const now = Date.now() as UnixTimestampMillis
254
254
  const batchedProgress = this.progress * chunkSize
255
255
  const lastRPS =
256
256
  (this.processedLastSecond * chunkSize) / ((now - this.lastSecondStarted) / 1000) || 0
@@ -12,7 +12,7 @@ import {
12
12
  Promisable,
13
13
  SKIP,
14
14
  StringMap,
15
- UnixTimestampMillisNumber,
15
+ UnixTimestampMillis,
16
16
  } from '@naturalcycles/js-lib'
17
17
  import through2Concurrent = require('through2-concurrent')
18
18
  import { yellow } from '../../colors/colors'
@@ -94,7 +94,7 @@ export interface TransformMapStats {
94
94
  countErrors: number
95
95
  countIn: number
96
96
  countOut: number
97
- started: UnixTimestampMillisNumber
97
+ started: UnixTimestampMillis
98
98
  }
99
99
 
100
100
  export interface TransformMapStatsSummary extends TransformMapStats {
@@ -141,7 +141,7 @@ export function transformMap<IN = any, OUT = IN>(
141
141
  logger = console,
142
142
  } = opt
143
143
 
144
- const started = Date.now()
144
+ const started = Date.now() as UnixTimestampMillis
145
145
  let index = -1
146
146
  let countOut = 0
147
147
  let isSettled = false
@@ -6,6 +6,7 @@ import {
6
6
  Mapper,
7
7
  Predicate,
8
8
  SKIP,
9
+ UnixTimestampMillis,
9
10
  } from '@naturalcycles/js-lib'
10
11
  import { yellow } from '../../colors/colors'
11
12
  import { AbortableTransform } from '../pipeline/pipeline'
@@ -88,7 +89,7 @@ export function transformMapSync<IN = any, OUT = IN>(
88
89
  logger = console,
89
90
  } = opt
90
91
 
91
- const started = Date.now()
92
+ const started = Date.now() as UnixTimestampMillis
92
93
  let index = -1
93
94
  let countOut = 0
94
95
  let isSettled = false
@@ -4,10 +4,10 @@ import {
4
4
  _since,
5
5
  DeferredPromise,
6
6
  localTime,
7
- NumberOfMilliseconds,
8
7
  NumberOfSeconds,
9
8
  pDefer,
10
9
  PositiveInteger,
10
+ UnixTimestampMillis,
11
11
  } from '@naturalcycles/js-lib'
12
12
  import { TransformTyped } from '../stream.model'
13
13
 
@@ -46,7 +46,7 @@ export function transformThrottle<T>(opt: TransformThrottleOptions): TransformTy
46
46
  const { throughput, interval, debug } = opt
47
47
 
48
48
  let count = 0
49
- let start: NumberOfMilliseconds
49
+ let start: UnixTimestampMillis
50
50
  let paused: DeferredPromise | undefined
51
51
  let timeout: NodeJS.Timeout | undefined
52
52
 
@@ -55,7 +55,7 @@ export function transformThrottle<T>(opt: TransformThrottleOptions): TransformTy
55
55
  async transform(item: T, _, cb) {
56
56
  // console.log('incoming', item, { paused: !!paused, count })
57
57
  if (!start) {
58
- start = Date.now()
58
+ start = Date.now() as UnixTimestampMillis
59
59
  timeout = setTimeout(() => onInterval(this), interval * 1000)
60
60
  if (debug) {
61
61
  console.log(`${localTime.now().toPretty()} transformThrottle started with`, {
@@ -106,7 +106,7 @@ export function transformThrottle<T>(opt: TransformThrottleOptions): TransformTy
106
106
  }
107
107
 
108
108
  count = 0
109
- start = Date.now()
109
+ start = Date.now() as UnixTimestampMillis
110
110
  timeout = setTimeout(() => onInterval(transform), interval * 1000)
111
111
  }
112
112
  }
@@ -3,7 +3,7 @@ import {
3
3
  AnyObject,
4
4
  BuildInfo,
5
5
  localTime,
6
- UnixTimestampNumber,
6
+ UnixTimestamp,
7
7
  } from '@naturalcycles/js-lib'
8
8
  import { fs2 } from '../fs/fs2'
9
9
  import { git2 } from './git2'
@@ -12,7 +12,7 @@ export interface GenerateBuildInfoOptions {
12
12
  /**
13
13
  * If set - this timestamp will be used, instead of "current time".
14
14
  */
15
- overrideTimestamp?: UnixTimestampNumber
15
+ overrideTimestamp?: UnixTimestamp
16
16
  }
17
17
 
18
18
  export function generateBuildInfo(opt: GenerateBuildInfoOptions = {}): BuildInfo {
package/src/util/exec2.ts CHANGED
@@ -4,7 +4,7 @@ import {
4
4
  AnyObject,
5
5
  AppError,
6
6
  NumberOfMilliseconds,
7
- UnixTimestampMillisNumber,
7
+ UnixTimestampMillis,
8
8
  } from '@naturalcycles/js-lib'
9
9
  import { dimGrey, dimRed, hasColors, white } from '../colors/colors'
10
10
 
@@ -49,7 +49,7 @@ class Exec2 {
49
49
  opt.log ??= true // by default log should be true, as we are printing the output
50
50
  opt.logStart ??= opt.log
51
51
  opt.logFinish ??= opt.log
52
- const started = Date.now()
52
+ const started = Date.now() as UnixTimestampMillis
53
53
  this.logStart(cmd, opt)
54
54
 
55
55
  const r = cp.spawnSync(cmd, opt.args, {
@@ -93,7 +93,7 @@ class Exec2 {
93
93
  const { cwd, env, passProcessEnv = true, timeout } = opt
94
94
  opt.logStart ??= opt.log ?? false
95
95
  opt.logFinish ??= opt.log ?? false
96
- const started = Date.now()
96
+ const started = Date.now() as UnixTimestampMillis
97
97
  this.logStart(cmd, opt)
98
98
 
99
99
  try {
@@ -146,7 +146,7 @@ class Exec2 {
146
146
  opt.log ??= true // by default log should be true, as we are printing the output
147
147
  opt.logStart ??= opt.log
148
148
  opt.logFinish ??= opt.log
149
- const started = Date.now()
149
+ const started = Date.now() as UnixTimestampMillis
150
150
  this.logStart(cmd, opt)
151
151
 
152
152
  await new Promise<void>((resolve, reject) => {
@@ -205,7 +205,7 @@ class Exec2 {
205
205
  opt.log ??= printWhileRunning // by default log should be true, as we are printing the output
206
206
  opt.logStart ??= opt.log
207
207
  opt.logFinish ??= opt.log
208
- const started = Date.now()
208
+ const started = Date.now() as UnixTimestampMillis
209
209
  this.logStart(cmd, opt)
210
210
  let stdout = ''
211
211
  let stderr = ''
@@ -274,7 +274,7 @@ class Exec2 {
274
274
  private logFinish(
275
275
  cmd: string,
276
276
  opt: SpawnOptions | ExecOptions,
277
- started: UnixTimestampMillisNumber,
277
+ started: UnixTimestampMillis,
278
278
  isSuccessful: boolean,
279
279
  ): void {
280
280
  if (isSuccessful && !opt.logFinish) return
package/src/util/git2.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import cp from 'node:child_process'
2
2
  import path from 'node:path'
3
- import type { UnixTimestampNumber } from '@naturalcycles/js-lib'
3
+ import type { UnixTimestamp } from '@naturalcycles/js-lib'
4
4
  import { grey } from '../colors/colors'
5
5
  import { exec2 } from './exec2'
6
6
 
@@ -88,8 +88,8 @@ class Git2 {
88
88
  return full ? sha : sha.slice(0, 7)
89
89
  }
90
90
 
91
- getCurrentCommitTimestamp(): UnixTimestampNumber {
92
- return Number(exec2.exec('git log -1 --format=%ct'))
91
+ getCurrentCommitTimestamp(): UnixTimestamp {
92
+ return Number(exec2.exec('git log -1 --format=%ct')) as UnixTimestamp
93
93
  }
94
94
 
95
95
  getCurrentBranchName(): string {
@@ -6,6 +6,8 @@ import {
6
6
  BaseDBEntity,
7
7
  NumberEnum,
8
8
  StringEnum,
9
+ UnixTimestamp,
10
+ UnixTimestampMillis,
9
11
  } from '@naturalcycles/js-lib'
10
12
  import { AlternativesSchema, AnySchema, ArraySchema, ObjectSchema } from 'joi'
11
13
  import { Joi } from './joi.extensions'
@@ -29,6 +31,13 @@ export const dateIntervalStringSchema = stringSchema.regex(DATE_INTERVAL_REGEX).
29
31
  'string.pattern.base': `must be a DateInterval string`,
30
32
  })
31
33
 
34
+ export const DATE_TIME_STRING_REGEX =
35
+ /^\d{4}-\d{2}-\d{2}(?:T\d{2}:\d{2}:\d{2}(?:\.\d{1,3})?(?:Z|[+-]\d{2}:\d{2})?)?$/
36
+
37
+ export const dateTimeStringSchema = stringSchema.regex(DATE_TIME_STRING_REGEX).messages({
38
+ 'string.pattern.base': `must be a DateTime string`,
39
+ })
40
+
32
41
  /**
33
42
  * Allows all values of a String Enum.
34
43
  */
@@ -112,25 +121,31 @@ const TS_2000 = 946684800 // 2000-01-01
112
121
  /**
113
122
  * Between years 1970 and 2050
114
123
  */
115
- export const unixTimestampSchema = numberSchema.integer().min(0).max(TS_2500)
124
+ export const unixTimestampSchema = numberSchema
125
+ .integer()
126
+ .min(0)
127
+ .max(TS_2500) as NumberSchema<UnixTimestamp>
116
128
  /**
117
129
  * Between years 2000 and 2050
118
130
  */
119
- export const unixTimestamp2000Schema = numberSchema.integer().min(TS_2000).max(TS_2500)
131
+ export const unixTimestamp2000Schema = numberSchema
132
+ .integer()
133
+ .min(TS_2000)
134
+ .max(TS_2500) as NumberSchema<UnixTimestamp>
120
135
  /**
121
136
  * Between years 1970 and 2050
122
137
  */
123
138
  export const unixTimestampMillisSchema = numberSchema
124
139
  .integer()
125
140
  .min(0)
126
- .max(TS_2500 * 1000)
141
+ .max(TS_2500 * 1000) as NumberSchema<UnixTimestampMillis>
127
142
  /**
128
143
  * Between years 2000 and 2050
129
144
  */
130
145
  export const unixTimestampMillis2000Schema = numberSchema
131
146
  .integer()
132
147
  .min(TS_2000 * 1000)
133
- .max(TS_2500 * 1000)
148
+ .max(TS_2500 * 1000) as NumberSchema<UnixTimestampMillis>
134
149
 
135
150
  // 2
136
151
  export const verSchema = numberSchema.optional().integer().min(1).max(100)
@@ -82,6 +82,7 @@ export function stringExtensions(joi: typeof Joi): Extension {
82
82
  }
83
83
 
84
84
  const DAYS = [0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
85
+
85
86
  // Based on: https://github.com/ajv-validator
86
87
  function isValidDate(parts: string[]): boolean {
87
88
  const year = Number(parts[1])