Skip to content

Commit

Permalink
fix: use branded UnixTimestamp
Browse files Browse the repository at this point in the history
  • Loading branch information
kirillgroshkov committed Nov 9, 2024
1 parent 3a7bb45 commit c6dcee6
Show file tree
Hide file tree
Showing 8 changed files with 217 additions and 207 deletions.
4 changes: 2 additions & 2 deletions src/deploy/deploy.model.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { UnixTimestampNumber } from '@naturalcycles/js-lib'
import type { UnixTimestamp } from '@naturalcycles/js-lib'

export interface DeployInfo {
gaeProject: string
Expand All @@ -12,7 +12,7 @@ export interface DeployInfo {
/**
* Unix timestamp of deployInfo.json being generated.
*/
ts: UnixTimestampNumber
ts: UnixTimestamp
}

export interface AppYaml extends Record<string, any> {
Expand Down
11 changes: 9 additions & 2 deletions src/deploy/deployHealthCheck.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
import { inspect, InspectOptions } from 'node:util'
import { _filterFalsyValues, _ms, _since, getFetcher, pDelay } from '@naturalcycles/js-lib'
import {
_filterFalsyValues,
_ms,
_since,
getFetcher,
pDelay,
UnixTimestampMillis,
} from '@naturalcycles/js-lib'
import { dimGrey, exec2, red } from '@naturalcycles/nodejs-lib'
import { coloredHttpCode } from '../server/request.log.util'

Expand Down Expand Up @@ -126,7 +133,7 @@ export async function deployHealthCheck(

console.log([`>>`, dimGrey(url), inspect({ attempt }, inspectOpt)].join(' '))

const started = Date.now()
const started = Date.now() as UnixTimestampMillis

const { err, statusCode = 0 } = await fetcher.doFetch({
url,
Expand Down
2 changes: 0 additions & 2 deletions src/sentry/sentry.shared.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ import {
StringMap,
} from '@naturalcycles/js-lib'
import { _inspect, InspectAnyOptions } from '@naturalcycles/nodejs-lib'
// eslint-disable-next-line import-x/no-duplicates
import type { Breadcrumb, NodeOptions, SeverityLevel } from '@sentry/node'
// eslint-disable-next-line import-x/no-duplicates
import type * as SentryLib from '@sentry/node'
import { BackendErrorRequestHandler, BackendRequestHandler, getRequestLogger } from '../index'

Expand Down
4 changes: 2 additions & 2 deletions src/server/deployInfo.util.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { _memoFn } from '@naturalcycles/js-lib'
import { _memoFn, localTime } from '@naturalcycles/js-lib'
import { fs2 } from '@naturalcycles/nodejs-lib'
import type { DeployInfo } from '../deploy'

Expand All @@ -21,6 +21,6 @@ function getDeployInfoStub(stub = ''): DeployInfo {
versionUrl: stub,
gitBranch: stub,
gitRev: stub,
ts: Math.floor(Date.now() / 1000),
ts: localTime.nowUnix(),
}
}
4 changes: 2 additions & 2 deletions src/server/simpleRequestLoggerMiddleware.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { _since } from '@naturalcycles/js-lib'
import { _since, UnixTimestampMillis } from '@naturalcycles/js-lib'
import { boldGrey, dimGrey } from '@naturalcycles/nodejs-lib'
import { BackendRequestHandler, onFinished } from '../index'
import { logRequest } from './request.log.util'
Expand Down Expand Up @@ -32,7 +32,7 @@ export function simpleRequestLoggerMiddleware(
const { logStart, logFinish } = cfg

return (req, res, next) => {
const started = Date.now()
const started = Date.now() as UnixTimestampMillis

if (logStart) {
req.log(['>>', req.method, boldGrey(req.url)].join(' '))
Expand Down
4 changes: 2 additions & 2 deletions src/test/globalSetup.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
const started = Date.now()
const started = Date.now() as UnixTimestampMillis

import { Server } from 'node:http'
import { AddressInfo } from 'node:net'
import { _since } from '@naturalcycles/js-lib'
import { _since, UnixTimestampMillis } from '@naturalcycles/js-lib'
import { createDefaultApp } from '..'
import { debugResource } from './debug.resource'

Expand Down
4 changes: 2 additions & 2 deletions src/test/globalTeardown.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { _since } from '@naturalcycles/js-lib'
import { _since, UnixTimestampMillis } from '@naturalcycles/js-lib'

/* eslint-disable import-x/no-anonymous-default-export, unicorn/no-anonymous-default-export */
// biome-ignore lint/style/noDefaultExport: ok
export default async (): Promise<void> => {
const started = Date.now()
const started = Date.now() as UnixTimestampMillis
// @ts-expect-error
await new Promise(resolve => global['__EXPRESS_SERVER__'].close(resolve as any))
console.log(`\nglobalTeardown.ts done in ${_since(started)}`)
Expand Down
391 changes: 198 additions & 193 deletions yarn.lock

Large diffs are not rendered by default.

0 comments on commit c6dcee6

Please sign in to comment.