-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
110 additions
and
165 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,38 @@ | ||
import { groupBy } from '../../utils/group.js' | ||
|
||
// `merge` can be "last", which refers to the previous result's mergeId: | ||
// - If there are no previous results, the current result's id is used | ||
// - If the previous result has no mergeId, its id is used | ||
// The new value is persisted in results. | ||
export const normalizeMergeId = function (targetResult, history) { | ||
return targetResult.mergeId === LAST_MERGE_ID | ||
? { ...targetResult, mergeId: replaceMergeIdLast(targetResult, history) } | ||
: targetResult | ||
} | ||
import { inspect } from 'util' | ||
|
||
import { v4 as uuidv4, validate as isUuid } from 'uuid' | ||
|
||
const LAST_MERGE_ID = 'last' | ||
import { UserError } from '../../error/main.js' | ||
|
||
const replaceMergeIdLast = function (targetResult, history) { | ||
if (history.length === 0) { | ||
return targetResult.id | ||
// Validate `merge` property | ||
export const normalizeMerge = function (value, name) { | ||
if (!isValidId(value) && value !== LAST_ID) { | ||
throw new UserError( | ||
`'${name}' must be "${LAST_ID}" or a UUID: ${inspect(value)}`, | ||
) | ||
} | ||
} | ||
|
||
const { id, mergeId = id } = history[history.length - 1] | ||
return mergeId | ||
// Validate `result.id`. | ||
// "last" is not persisted since it is normalized first. | ||
export const isValidId = function (value) { | ||
return isUuid(value) | ||
} | ||
|
||
// Group either metadata or rawResults by mergeId: | ||
// - They must both have the following properties: `id`, `mergeId` | ||
// `result.mergeId` defaults to `result.id` | ||
// - This allows merging to previous results even when the user did not | ||
// previously intend to | ||
// - However, the default value is assigned at load time, it is not persisted | ||
export const groupByMergeId = function (metadataOrRawResults) { | ||
return Object.values(groupBy(metadataOrRawResults, getMergeId)) | ||
// `merge` can be "last", which refers to the previous result's id. | ||
// If there are no previous results, a new UUIDv4 is generated. | ||
export const normalizeId = function (targetResult, history) { | ||
if (targetResult.id !== LAST_ID) { | ||
return targetResult | ||
} | ||
|
||
const id = | ||
history.length === 0 ? getDefaultId() : history[history.length - 1].id | ||
return { ...targetResult, id } | ||
} | ||
|
||
const getMergeId = function ({ id, mergeId = id }) { | ||
return mergeId | ||
const LAST_ID = 'last' | ||
|
||
export const getDefaultId = function () { | ||
return uuidv4() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.