fix: keep project entity selection and ignore placeholder hits
This commit is contained in:
@@ -88,6 +88,12 @@ export function withoutWhitelistedHits<T extends GroupableHit>(hits: T[], whitel
|
||||
return hits.filter((hit) => !excluded.has(whitelistKey(hit)));
|
||||
}
|
||||
|
||||
/** A later run must not turn an existing Velum placeholder plus adjacent text into a new entity. */
|
||||
export function withoutPlaceholderHits<T extends { original: string; type: string }>(hits: T[]): T[] {
|
||||
const placeholder = /(?<![\p{L}\p{N}])[A-Z][A-Z0-9]*_\d{2,}(?![\p{L}\p{N}])/u;
|
||||
return hits.filter((hit) => hit.type === "PASSWORT" || !placeholder.test(hit.original));
|
||||
}
|
||||
|
||||
export function withoutWhitelistedRules<T extends { type: string; value: string }>(
|
||||
rules: T[], whitelist: ProjectWhitelistEntry[],
|
||||
): T[] {
|
||||
|
||||
@@ -2,7 +2,7 @@ import { createHash, randomUUID } from "node:crypto";
|
||||
import { constants as fsConstants, promises as fs } from "node:fs";
|
||||
import { basename, dirname, extname, join, relative, resolve, sep } from "node:path";
|
||||
import { environment } from "@raycast/api";
|
||||
import type { PlaceholderMapping } from "../types";
|
||||
import type { EntityType, PlaceholderMapping } from "../types";
|
||||
import { whitelistKey } from "./project-whitelist";
|
||||
import type { ProjectWhitelistEntry } from "./project-whitelist";
|
||||
|
||||
@@ -68,6 +68,36 @@ export function whitelistPath(projectPath: string, support = environment.support
|
||||
return join(projectDataRoot(projectPath, support), "whitelist.json");
|
||||
}
|
||||
|
||||
export function entityTypesPath(projectPath: string, support = environment.supportPath): string {
|
||||
return join(projectDataRoot(projectPath, support), "entity-types.json");
|
||||
}
|
||||
|
||||
export async function loadProjectEntityTypes(projectPath: string, support?: string): Promise<EntityType[] | null> {
|
||||
try {
|
||||
const value = JSON.parse(await fs.readFile(entityTypesPath(projectPath, support), "utf8")) as unknown;
|
||||
if (!Array.isArray(value) || value.some((type) => typeof type !== "string" || !type)) {
|
||||
throw new Error("Ungültige Kategorienauswahl für dieses Projekt.");
|
||||
}
|
||||
return [...new Set(value)];
|
||||
} catch (error) {
|
||||
if ((error as NodeJS.ErrnoException).code === "ENOENT") return null;
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
export async function saveProjectEntityTypes(projectPath: string, types: EntityType[], support?: string): Promise<void> {
|
||||
const path = entityTypesPath(projectPath, support);
|
||||
await fs.mkdir(dirname(path), { recursive: true, mode: 0o700 });
|
||||
const temp = `${path}.${randomUUID()}.tmp`;
|
||||
try {
|
||||
await fs.writeFile(temp, JSON.stringify([...new Set(types)]), { encoding: "utf8", mode: 0o600 });
|
||||
await fs.rename(temp, path);
|
||||
} catch (error) {
|
||||
await fs.rm(temp, { force: true });
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
export async function loadProjectWhitelist(projectPath: string, support?: string): Promise<ProjectWhitelistEntry[]> {
|
||||
try {
|
||||
const value = JSON.parse(await fs.readFile(whitelistPath(projectPath, support), "utf8")) as unknown;
|
||||
|
||||
Reference in New Issue
Block a user