@featurevisor/core
Advanced tools
Comparing version 1.18.1 to 1.19.0
@@ -6,2 +6,13 @@ # Change Log | ||
# [1.19.0](https://github.com/featurevisor/featurevisor/compare/v1.18.1...v1.19.0) (2024-04-26) | ||
### Features | ||
* find duplicate segments with authors info ([#299](https://github.com/featurevisor/featurevisor/issues/299)) ([5008066](https://github.com/featurevisor/featurevisor/commit/5008066128fb7c732b633856dcffcb768f52c88c)) | ||
## [1.18.1](https://github.com/featurevisor/featurevisor/compare/v1.18.0...v1.18.1) (2024-04-23) | ||
@@ -8,0 +19,0 @@ |
import { SegmentKey } from "@featurevisor/types"; | ||
import { Datasource } from "../datasource"; | ||
export declare function findDuplicateSegments(datasource: Datasource): Promise<SegmentKey[][]>; | ||
import { Dependencies } from "../dependencies"; | ||
export interface DuplicateSegmentsOptions { | ||
authors?: boolean; | ||
} | ||
export interface DuplicateSegmentsResult { | ||
segments: SegmentKey[]; | ||
authors?: string[]; | ||
} | ||
export declare function findDuplicateSegments(deps: Dependencies, options?: DuplicateSegmentsOptions): Promise<DuplicateSegmentsResult[]>; |
@@ -41,13 +41,16 @@ "use strict"; | ||
var crypto = require("crypto"); | ||
function findDuplicateSegments(datasource) { | ||
function findDuplicateSegments(deps, options) { | ||
if (options === void 0) { options = {}; } | ||
return __awaiter(this, void 0, void 0, function () { | ||
var segments, segmentsWithHash, _i, segments_1, segmentKey, segment, conditions, hash, groupedSegments, result; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, datasource.listSegments()]; | ||
var datasource, segments, segmentsWithHash, _i, segments_1, segmentKey, segment, conditions, hash, groupedSegments, duplicateSegments, result, _loop_1, _a, duplicateSegments_1, segmentKeys; | ||
return __generator(this, function (_b) { | ||
switch (_b.label) { | ||
case 0: | ||
datasource = deps.datasource; | ||
return [4 /*yield*/, datasource.listSegments()]; | ||
case 1: | ||
segments = _a.sent(); | ||
segments = _b.sent(); | ||
segmentsWithHash = []; | ||
_i = 0, segments_1 = segments; | ||
_a.label = 2; | ||
_b.label = 2; | ||
case 2: | ||
@@ -58,3 +61,3 @@ if (!(_i < segments_1.length)) return [3 /*break*/, 5]; | ||
case 3: | ||
segment = _a.sent(); | ||
segment = _b.sent(); | ||
conditions = JSON.stringify(segment.conditions); | ||
@@ -66,3 +69,3 @@ hash = crypto.createHash("sha256").update(conditions).digest("hex"); | ||
}); | ||
_a.label = 4; | ||
_b.label = 4; | ||
case 4: | ||
@@ -80,4 +83,52 @@ _i++; | ||
}, {}); | ||
result = Object.values(groupedSegments).filter(function (segmentKeys) { return segmentKeys.length > 1; }); | ||
return [2 /*return*/, result]; | ||
duplicateSegments = Object.values(groupedSegments).filter(function (segmentKeys) { return segmentKeys.length > 1; }); | ||
result = []; | ||
_loop_1 = function (segmentKeys) { | ||
var entry, historyEntries_1, _c, segmentKeys_1, segmentKey, entries, authors; | ||
return __generator(this, function (_d) { | ||
switch (_d.label) { | ||
case 0: | ||
entry = { | ||
segments: segmentKeys, | ||
}; | ||
if (!options.authors) return [3 /*break*/, 5]; | ||
historyEntries_1 = []; | ||
_c = 0, segmentKeys_1 = segmentKeys; | ||
_d.label = 1; | ||
case 1: | ||
if (!(_c < segmentKeys_1.length)) return [3 /*break*/, 4]; | ||
segmentKey = segmentKeys_1[_c]; | ||
return [4 /*yield*/, datasource.listHistoryEntries("segment", segmentKey)]; | ||
case 2: | ||
entries = _d.sent(); | ||
entries.forEach(function (entry) { | ||
historyEntries_1.push(entry); | ||
}); | ||
_d.label = 3; | ||
case 3: | ||
_c++; | ||
return [3 /*break*/, 1]; | ||
case 4: | ||
authors = Array.from(new Set(historyEntries_1.map(function (entry) { return entry.author; }))); | ||
entry.authors = authors; | ||
_d.label = 5; | ||
case 5: | ||
result.push(entry); | ||
return [2 /*return*/]; | ||
} | ||
}); | ||
}; | ||
_a = 0, duplicateSegments_1 = duplicateSegments; | ||
_b.label = 6; | ||
case 6: | ||
if (!(_a < duplicateSegments_1.length)) return [3 /*break*/, 9]; | ||
segmentKeys = duplicateSegments_1[_a]; | ||
return [5 /*yield**/, _loop_1(segmentKeys)]; | ||
case 7: | ||
_b.sent(); | ||
_b.label = 8; | ||
case 8: | ||
_a++; | ||
return [3 /*break*/, 6]; | ||
case 9: return [2 /*return*/, result]; | ||
} | ||
@@ -84,0 +135,0 @@ }); |
@@ -0,2 +1,3 @@ | ||
import { DuplicateSegmentsOptions } from "./findDuplicateSegments"; | ||
import { Dependencies } from "../dependencies"; | ||
export declare function findDuplicateSegmentsInProject(deps: Dependencies): Promise<void>; | ||
export declare function findDuplicateSegmentsInProject(deps: Dependencies, options?: DuplicateSegmentsOptions): Promise<void>; |
@@ -41,12 +41,12 @@ "use strict"; | ||
var findDuplicateSegments_1 = require("./findDuplicateSegments"); | ||
function findDuplicateSegmentsInProject(deps) { | ||
function findDuplicateSegmentsInProject(deps, options) { | ||
if (options === void 0) { options = {}; } | ||
return __awaiter(this, void 0, void 0, function () { | ||
var datasource, duplicates; | ||
var duplicates; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
datasource = deps.datasource; | ||
return [4 /*yield*/, (0, findDuplicateSegments_1.findDuplicateSegments)(datasource)]; | ||
case 0: return [4 /*yield*/, (0, findDuplicateSegments_1.findDuplicateSegments)(deps, options)]; | ||
case 1: | ||
duplicates = _a.sent(); | ||
console.log(""); | ||
if (duplicates.length === 0) { | ||
@@ -56,5 +56,12 @@ console.log("No duplicate segments found"); | ||
} | ||
console.log("Found ".concat(duplicates.length, " duplicates:\n")); | ||
duplicates.forEach(function (segmentKeys) { | ||
console.log(" - ".concat(segmentKeys.join(", "))); | ||
console.log("Found ".concat(duplicates.length, " duplicate(s):\n")); | ||
duplicates.forEach(function (entry) { | ||
if (options.authors) { | ||
console.log(" - Segments: ".concat(entry.segments.join(", "))); | ||
console.log(" Authors: ".concat(entry.authors && entry.authors.join(", "))); | ||
console.log(""); | ||
} | ||
else { | ||
console.log(" - ".concat(entry.segments.join(", "))); | ||
} | ||
}); | ||
@@ -61,0 +68,0 @@ return [2 /*return*/]; |
{ | ||
"name": "@featurevisor/core", | ||
"version": "1.18.1", | ||
"version": "1.19.0", | ||
"description": "Core package of Featurevisor for Node.js usage", | ||
@@ -60,3 +60,3 @@ "main": "lib/index.js", | ||
}, | ||
"gitHead": "5a1572d908a0aa9fcdcb5fe208cee8c0f17f7b4f" | ||
"gitHead": "7164b8bdd056f9302ead794acf7424df98345f45" | ||
} |
import * as crypto from "crypto"; | ||
import { SegmentKey } from "@featurevisor/types"; | ||
import { HistoryEntry, SegmentKey } from "@featurevisor/types"; | ||
import { Datasource } from "../datasource"; | ||
import { Dependencies } from "../dependencies"; | ||
export async function findDuplicateSegments(datasource: Datasource): Promise<SegmentKey[][]> { | ||
export interface DuplicateSegmentsOptions { | ||
authors?: boolean; | ||
} | ||
export interface DuplicateSegmentsResult { | ||
segments: SegmentKey[]; | ||
authors?: string[]; | ||
} | ||
export async function findDuplicateSegments( | ||
deps: Dependencies, | ||
options: DuplicateSegmentsOptions = {}, | ||
): Promise<DuplicateSegmentsResult[]> { | ||
const { datasource } = deps; | ||
const segments = await datasource.listSegments(); | ||
@@ -33,5 +47,31 @@ | ||
const result = Object.values(groupedSegments).filter((segmentKeys) => segmentKeys.length > 1); | ||
const duplicateSegments = Object.values(groupedSegments).filter( | ||
(segmentKeys) => segmentKeys.length > 1, | ||
); | ||
const result: DuplicateSegmentsResult[] = []; | ||
for (const segmentKeys of duplicateSegments) { | ||
const entry: DuplicateSegmentsResult = { | ||
segments: segmentKeys, | ||
}; | ||
if (options.authors) { | ||
const historyEntries: HistoryEntry[] = []; | ||
for (const segmentKey of segmentKeys) { | ||
const entries = await datasource.listHistoryEntries("segment", segmentKey); | ||
entries.forEach((entry) => { | ||
historyEntries.push(entry); | ||
}); | ||
} | ||
const authors = Array.from(new Set(historyEntries.map((entry) => entry.author))); | ||
entry.authors = authors; | ||
} | ||
result.push(entry); | ||
} | ||
return result; | ||
} |
@@ -1,8 +0,11 @@ | ||
import { findDuplicateSegments } from "./findDuplicateSegments"; | ||
import { findDuplicateSegments, DuplicateSegmentsOptions } from "./findDuplicateSegments"; | ||
import { Dependencies } from "../dependencies"; | ||
export async function findDuplicateSegmentsInProject(deps: Dependencies) { | ||
const { datasource } = deps; | ||
export async function findDuplicateSegmentsInProject( | ||
deps: Dependencies, | ||
options: DuplicateSegmentsOptions = {}, | ||
) { | ||
const duplicates = await findDuplicateSegments(deps, options); | ||
const duplicates = await findDuplicateSegments(datasource); | ||
console.log(""); | ||
@@ -14,7 +17,13 @@ if (duplicates.length === 0) { | ||
console.log(`Found ${duplicates.length} duplicates:\n`); | ||
console.log(`Found ${duplicates.length} duplicate(s):\n`); | ||
duplicates.forEach((segmentKeys) => { | ||
console.log(` - ${segmentKeys.join(", ")}`); | ||
duplicates.forEach((entry) => { | ||
if (options.authors) { | ||
console.log(` - Segments: ${entry.segments.join(", ")}`); | ||
console.log(` Authors: ${entry.authors && entry.authors.join(", ")}`); | ||
console.log(""); | ||
} else { | ||
console.log(` - ${entry.segments.join(", ")}`); | ||
} | ||
}); | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
1070273
13733