Skip to content

Commit

Permalink
Move files
Browse files Browse the repository at this point in the history
  • Loading branch information
ehmicky committed Jan 2, 2022
1 parent e658780 commit bf8f47a
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 40 deletions.
2 changes: 1 addition & 1 deletion src/config/main.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { normalizeDeltas } from '../history/delta/main.js'
import { normalizeDeltas } from '../history/delta/normalize.js'

import { addDefaultConfig } from './default.js'
import { loadConfig } from './load/main.js'
Expand Down
2 changes: 1 addition & 1 deletion src/history/data/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import inquirer from 'inquirer'
import { UserError } from '../../error/main.js'
import { isTtyInput } from '../../report/tty.js'
import { getDeltaError } from '../delta/error.js'
import { findByDelta } from '../delta/main.js'
import { findByDelta } from '../delta/find.js'
import { compressRawResult } from '../normalize/compress.js'
import { loadRawResults } from '../normalize/load.js'

Expand Down
38 changes: 38 additions & 0 deletions src/history/delta/find.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { addDeltaError } from './error.js'
import { findFormat } from './formats/main.js'

// Get previous rawResults index by rawResult delta.
// `rawResults` must be sorted from most to least recent.
// In general, most delta formats look for the first rawResult after the delta.
// - This allows users to specify loose deltas without errors, such as
// "100" even if there are only 3 rawResults.
// - However, few formats look for the last rawResult before the delta instead
// since it makes more sense for those.
// Returns -1 when no delta is found:
// - Either because:
// - There are no rawResults
// - The delta points to a time in the future or to a non-existing reference
// - If the delta has a syntax or semantics that we know is always erroneous,
// we throw instead
// - When this happens with:
// - `show|remove` delta: we fail hard because there is no rawResult to
// report
// - `since` configuration property: `rawResult.history` is empty
// - `diff` configuration property: `stats.diff` is `undefined`
export const findByDelta = async function (
rawResults,
{ type, value, delta, name },
cwd,
) {
if (rawResults.length === 0) {
return -1
}

const { find } = findFormat(type)

try {
return await find(rawResults, value, cwd)
} catch (error) {
throw addDeltaError(error, { type, delta, name })
}
}
38 changes: 1 addition & 37 deletions src/history/delta/main.js → src/history/delta/normalize.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { UserError } from '../../error/main.js'
import { findValue } from '../../utils/find.js'

import { getDeltaProp, addDeltaError } from './error.js'
import { FORMATS, findFormat } from './formats/main.js'
import { FORMATS } from './formats/main.js'

// Several configuration properties targets a previous rawResults using a delta,
// which can an integer, date/time, rawResult.id or git commit.
Expand Down Expand Up @@ -52,39 +52,3 @@ const parseDelta = function ({ format: { parse, type }, delta, name }) {
throw addDeltaError(error, { type, delta, name })
}
}

// Get previous rawResults index by rawResult delta.
// `rawResults` must be sorted from most to least recent.
// In general, most delta formats look for the first rawResult after the delta.
// - This allows users to specify loose deltas without errors, such as
// "100" even if there are only 3 rawResults.
// - However, few formats look for the last rawResult before the delta instead
// since it makes more sense for those.
// Returns -1 when no delta is found:
// - Either because:
// - There are no rawResults
// - The delta points to a time in the future or to a non-existing reference
// - If the delta has a syntax or semantics that we know is always erroneous,
// we throw instead
// - When this happens with:
// - `show|remove` delta: we fail hard because there is no rawResult to
// report
// - `since` configuration property: `rawResult.history` is empty
// - `diff` configuration property: `stats.diff` is `undefined`
export const findByDelta = async function (
rawResults,
{ type, value, delta, name },
cwd,
) {
if (rawResults.length === 0) {
return -1
}

const { find } = findFormat(type)

try {
return await find(rawResults, value, cwd)
} catch (error) {
throw addDeltaError(error, { type, delta, name })
}
}
2 changes: 1 addition & 1 deletion src/history/delta/since.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { findByDelta } from './main.js'
import { findByDelta } from './find.js'

// The `since` configuration property is used to limit the number of results
// shown in `result.history` which is used with time series reporters.
Expand Down

0 comments on commit bf8f47a

Please sign in to comment.