refactor: format markdown files using prettier, fix spelling concerns, reduce Taskfile bloat

This commit is contained in:
sam committed 2026-09-25 01:10:28 +10:00
1 parent 2051ca94d2
commit 2e00777f07
608 files changed
+63317 -10219

No files matched your search

+5 -2
View File
@@ -33,12 +33,15 @@ function onOpenChange(open: boolean) {
</AlertDialogMedia>
<AlertDialogTitle>Delete this mapping?</AlertDialogTitle>
<AlertDialogDescription>
"{{ pendingDelete?.name }}" will be removed. Anything bound to it stops resolving.
"{{ pendingDelete?.name }}" will be removed. Anything bound to it
stops resolving.
</AlertDialogDescription>
</AlertDialogHeader>
<AlertDialogFooter>
<AlertDialogCancel @click="cancelDelete">Cancel</AlertDialogCancel>
<AlertDialogAction variant="destructive" @click="confirmDelete">Delete</AlertDialogAction>
<AlertDialogAction variant="destructive" @click="confirmDelete"
>Delete</AlertDialogAction
>
</AlertDialogFooter>
</AlertDialogContent>
</AlertDialog>
+30 -6
View File
@@ -1,7 +1,13 @@
<script setup lang="ts">
import { Alert, AlertDescription } from "@/components/ui/alert";
import { Button } from "@/components/ui/button";
import { Card, CardContent, CardFooter, CardHeader, CardTitle } from "@/components/ui/card";
import {
Card,
CardContent,
CardFooter,
CardHeader,
CardTitle,
} from "@/components/ui/card";
import {
Dialog,
DialogContent,
@@ -15,7 +21,16 @@ import MappingActionError from "./MappingActionError.vue";
import MappingFieldsTable from "./MappingFieldsTable.vue";
import MappingForm from "./MappingForm.vue";
import PayloadTree from "./PayloadTree.vue";
import { actionError, addField, closeEditor, draft, editorOpen, runPreview, saveMapping, saving } from "./state";
import {
actionError,
addField,
closeEditor,
draft,
editorOpen,
runPreview,
saveMapping,
saving,
} from "./state";
/**
* One editing session, in an overlay: the mapping's own fields, the fields
@@ -34,9 +49,12 @@ function onOpenChange(open: boolean) {
<Dialog :open="editorOpen" @update:open="onOpenChange">
<DialogContent class="max-h-[85vh] overflow-y-auto sm:max-w-3xl">
<DialogHeader>
<DialogTitle>{{ draft.id === null ? "New mapping" : "Edit mapping" }}</DialogTitle>
<DialogTitle>{{
draft.id === null ? "New mapping" : "Edit mapping"
}}</DialogTitle>
<DialogDescription>
Bind named fields to JSON paths from a real captured event, ready for a playbook binding.
Bind named fields to JSON paths from a real captured event, ready for
a playbook binding.
</DialogDescription>
</DialogHeader>
@@ -66,8 +84,14 @@ function onOpenChange(open: boolean) {
<Alert v-if="draft.payloadError" variant="destructive">
<AlertDescription>{{ draft.payloadError }}</AlertDescription>
</Alert>
<PayloadTree v-else-if="draft.payload !== null" :value="draft.payload" @pick="addField" />
<p v-else class="text-sm text-fg-muted">Pick a captured event above to see its payload.</p>
<PayloadTree
v-else-if="draft.payload !== null"
:value="draft.payload"
@pick="addField"
/>
<p v-else class="text-sm text-fg-muted">
Pick a captured event above to see its payload.
</p>
</CardContent>
</Card>
+43 -9
View File
@@ -4,7 +4,14 @@ import { Trash2 } from "@lucide/vue";
import { Button } from "@/components/ui/button";
import { Checkbox } from "@/components/ui/checkbox";
import { Input } from "@/components/ui/input";
import { Select, SelectContent, SelectGroup, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select";
import {
Select,
SelectContent,
SelectGroup,
SelectItem,
SelectTrigger,
SelectValue,
} from "@/components/ui/select";
import { TableCell, TableRow } from "@/components/ui/table";
import { FIELD_TYPES, asFieldType } from "./mapping-fields";
import MappingPreviewStatus from "./MappingPreviewStatus.vue";
@@ -22,8 +29,15 @@ import type { MappingField, Preview, PreviewFailure } from "./state";
* table cell at 720px, and a segmented control there would push the row wider
* than the dialog it sits in.
*/
defineProps<{ field: MappingField; preview: Preview | null; failure?: PreviewFailure }>();
const emit = defineEmits<{ update: [patch: Partial<MappingField>]; remove: [] }>();
defineProps<{
field: MappingField;
preview: Preview | null;
failure?: PreviewFailure;
}>();
const emit = defineEmits<{
update: [patch: Partial<MappingField>];
remove: [];
}>();
</script>
<template>
@@ -36,16 +50,25 @@ const emit = defineEmits<{ update: [patch: Partial<MappingField>]; remove: [] }>
/>
</TableCell>
<TableCell class="font-mono text-xs">
<span class="block max-w-56 truncate" :title="field.path">{{ field.path }}</span>
<span class="block max-w-56 truncate" :title="field.path">{{
field.path
}}</span>
</TableCell>
<TableCell>
<Select :model-value="field.type" @update:model-value="(value) => emit('update', { type: asFieldType(value) })">
<Select
:model-value="field.type"
@update:model-value="
(value) => emit('update', { type: asFieldType(value) })
"
>
<SelectTrigger size="sm" :aria-label="`Type for ${field.name}`">
<SelectValue />
</SelectTrigger>
<SelectContent>
<SelectGroup>
<SelectItem v-for="type in FIELD_TYPES" :key="type" :value="type">{{ type }}</SelectItem>
<SelectItem v-for="type in FIELD_TYPES" :key="type" :value="type">{{
type
}}</SelectItem>
</SelectGroup>
</SelectContent>
</Select>
@@ -54,14 +77,25 @@ const emit = defineEmits<{ update: [patch: Partial<MappingField>]; remove: [] }>
<Checkbox
:model-value="field.required"
:aria-label="`Required: ${field.name}`"
@update:model-value="(value) => emit('update', { required: value === true })"
@update:model-value="
(value) => emit('update', { required: value === true })
"
/>
</TableCell>
<TableCell>
<MappingPreviewStatus :field="field" :preview="preview" :failure="failure" />
<MappingPreviewStatus
:field="field"
:preview="preview"
:failure="failure"
/>
</TableCell>
<TableCell>
<Button variant="ghost" size="icon-xs" :aria-label="`Remove ${field.name}`" @click="emit('remove')">
<Button
variant="ghost"
size="icon-xs"
:aria-label="`Remove ${field.name}`"
@click="emit('remove')"
>
<Trash2 />
</Button>
</TableCell>
+17 -3
View File
@@ -1,7 +1,13 @@
<script setup lang="ts">
import { computed } from "vue";
import { Table, TableBody, TableHead, TableHeader, TableRow } from "@/components/ui/table";
import {
Table,
TableBody,
TableHead,
TableHeader,
TableRow,
} from "@/components/ui/table";
import MappingFieldRow from "./MappingFieldRow.vue";
import { draft, removeField, updateField, type PreviewFailure } from "./state";
@@ -18,12 +24,20 @@ const preview = computed(() => draft.value.preview);
/** Preview failures are keyed by field name: the daemon reports a failure by
* name, and a field is what the operator renamed. */
const failureByField = computed(
() => new Map<string, PreviewFailure>((preview.value?.failures || []).map((failure) => [failure.field_name, failure])),
() =>
new Map<string, PreviewFailure>(
(preview.value?.failures || []).map((failure) => [
failure.field_name,
failure,
]),
),
);
</script>
<template>
<p v-if="!fields.length" class="py-3 text-sm text-fg-muted">Click a value in the payload to bind a field.</p>
<p v-if="!fields.length" class="py-3 text-sm text-fg-muted">
Click a value in the payload to bind a field.
</p>
<Table v-else>
<TableHeader>
+32 -6
View File
@@ -3,10 +3,24 @@ import { computed } from "vue";
import { Input } from "@/components/ui/input";
import { Label } from "@/components/ui/label";
import { Select, SelectContent, SelectGroup, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select";
import {
Select,
SelectContent,
SelectGroup,
SelectItem,
SelectTrigger,
SelectValue,
} from "@/components/ui/select";
import { ago } from "@/lib/format";
import { eventTypeLabel } from "@/captures/event-types";
import { captures, capturesEnabled, draft, eventTypes, selectCapture, type Capture } from "./state";
import {
captures,
capturesEnabled,
draft,
eventTypes,
selectCapture,
type Capture,
} from "./state";
/**
* The mapping's own fields: the name it is saved under, the organisational
@@ -24,7 +38,9 @@ import { captures, capturesEnabled, draft, eventTypes, selectCapture, type Captu
* item value outright. */
const NO_CAPTURE = "none";
const captureValue = computed(() => (draft.value.captureId === null ? NO_CAPTURE : String(draft.value.captureId)));
const captureValue = computed(() =>
draft.value.captureId === null ? NO_CAPTURE : String(draft.value.captureId),
);
function onCaptureChange(value: unknown): void {
selectCapture(String(value));
@@ -58,7 +74,11 @@ const captureHint = computed(() => {
</SelectTrigger>
<SelectContent>
<SelectGroup>
<SelectItem v-for="type in eventTypes" :key="type.id" :value="type.id">
<SelectItem
v-for="type in eventTypes"
:key="type.id"
:value="type.id"
>
{{ eventTypeLabel(type.id, eventTypes) }}
</SelectItem>
</SelectGroup>
@@ -79,8 +99,14 @@ const captureHint = computed(() => {
</SelectTrigger>
<SelectContent>
<SelectGroup>
<SelectItem :value="NO_CAPTURE">— pick a captured event —</SelectItem>
<SelectItem v-for="capture in captures" :key="capture.id" :value="String(capture.id)">
<SelectItem :value="NO_CAPTURE"
>— pick a captured event —</SelectItem
>
<SelectItem
v-for="capture in captures"
:key="capture.id"
:value="String(capture.id)"
>
{{ captureLabel(capture) }}
</SelectItem>
</SelectGroup>
+25 -11
View File
@@ -12,18 +12,32 @@ import type { MappingField, Preview, PreviewFailure } from "./state";
* previewed must never render as though it passed -- an unresolved field is not
* the same claim as a resolved one.
*/
const props = defineProps<{ field: MappingField; preview: Preview | null; failure?: PreviewFailure }>();
const props = defineProps<{
field: MappingField;
preview: Preview | null;
failure?: PreviewFailure;
}>();
const status = computed<{ variant: "ok" | "danger" | "idle"; text: string }>(() => {
if (!props.preview) return { variant: "idle", text: "not previewed" };
if (props.failure) return { variant: "danger", text: props.failure.reason };
if (Object.prototype.hasOwnProperty.call(props.preview.values || {}, props.field.name)) {
return { variant: "ok", text: JSON.stringify(props.preview.values?.[props.field.name]) };
}
// Absent from values and absent from failures: an optional field the payload
// did not carry, which is not a failure.
return { variant: "idle", text: "skipped (optional)" };
});
const status = computed<{ variant: "ok" | "danger" | "idle"; text: string }>(
() => {
if (!props.preview) return { variant: "idle", text: "not previewed" };
if (props.failure) return { variant: "danger", text: props.failure.reason };
if (
Object.prototype.hasOwnProperty.call(
props.preview.values || {},
props.field.name,
)
) {
return {
variant: "ok",
text: JSON.stringify(props.preview.values?.[props.field.name]),
};
}
// Absent from values and absent from failures: an optional field the payload
// did not carry, which is not a failure.
return { variant: "idle", text: "skipped (optional)" };
},
);
</script>
<template>
+19 -6
View File
@@ -9,20 +9,33 @@ import { eventTypes, type Mapping } from "./state";
/** One saved mapping's summary row. Both of its actions are the page's, not the
* row's: editing opens the editor overlay, deleting opens the confirmation. */
defineProps<{ mapping: Mapping }>();
const emit = defineEmits<{ edit: [mapping: Mapping]; delete: [mapping: Mapping] }>();
const emit = defineEmits<{
edit: [mapping: Mapping];
delete: [mapping: Mapping];
}>();
</script>
<template>
<TableRow>
<TableCell class="font-medium">{{ mapping.name }}</TableCell>
<TableCell class="font-mono text-fg-muted">{{ eventTypeLabel(mapping.event_type_id, eventTypes) }}</TableCell>
<TableCell class="tabular-nums">{{ mapping.fields?.length ?? 0 }}</TableCell>
<TableCell class="font-mono text-fg-muted">{{
eventTypeLabel(mapping.event_type_id, eventTypes)
}}</TableCell>
<TableCell class="tabular-nums">{{
mapping.fields?.length ?? 0
}}</TableCell>
<TableCell class="tabular-nums">{{ matchCountLabel(mapping) }}</TableCell>
<TableCell class="text-fg-muted">{{ mapping.match_count ? ago(mapping.last_matched_at) : "—" }}</TableCell>
<TableCell class="text-fg-muted">{{
mapping.match_count ? ago(mapping.last_matched_at) : "—"
}}</TableCell>
<TableCell>
<div class="flex justify-end gap-2">
<Button variant="outline" size="xs" @click="emit('edit', mapping)">Edit</Button>
<Button variant="destructive" size="xs" @click="emit('delete', mapping)">Delete</Button>
<Button variant="outline" size="xs" @click="emit('edit', mapping)"
>Edit</Button
>
<Button variant="destructive" size="xs" @click="emit('delete', mapping)"
>Delete</Button
>
</div>
</TableCell>
</TableRow>
+5 -1
View File
@@ -31,7 +31,11 @@ onMounted(loadMappings);
</Button>
</div>
<MappingActionError v-if="actionError" class="mb-4" :failure="actionError" />
<MappingActionError
v-if="actionError"
class="mb-4"
:failure="actionError"
/>
<MappingsTable />
+24 -4
View File
@@ -1,10 +1,27 @@
<script setup lang="ts">
import { Card, CardContent } from "@/components/ui/card";
import { Empty, EmptyDescription, EmptyHeader, EmptyTitle } from "@/components/ui/empty";
import {
Empty,
EmptyDescription,
EmptyHeader,
EmptyTitle,
} from "@/components/ui/empty";
import { Skeleton } from "@/components/ui/skeleton";
import { Table, TableBody, TableHead, TableHeader, TableRow } from "@/components/ui/table";
import {
Table,
TableBody,
TableHead,
TableHeader,
TableRow,
} from "@/components/ui/table";
import MappingRow from "./MappingRow.vue";
import { listLoading, loadError, mappings, requestDelete, startEdit } from "./state";
import {
listLoading,
loadError,
mappings,
requestDelete,
startEdit,
} from "./state";
/**
* The saved mappings, in all four states: still loading, unreadable, none yet,
@@ -30,7 +47,10 @@ import { listLoading, loadError, mappings, requestDelete, startEdit } from "./st
<Empty v-else-if="!mappings.length">
<EmptyHeader>
<EmptyTitle>No mappings yet</EmptyTitle>
<EmptyDescription>Create one from a captured event to reuse its fields in a future playbook binding.</EmptyDescription>
<EmptyDescription
>Create one from a captured event to reuse its fields in a future
playbook binding.</EmptyDescription
>
</EmptyHeader>
</Empty>
+42 -20
View File
@@ -1,7 +1,12 @@
<script setup lang="ts">
import { computed } from "vue";
import { fieldTypeFromValue, pathAppendIndex, pathAppendKey, type FieldPick } from "./mapping-fields";
import {
fieldTypeFromValue,
pathAppendIndex,
pathAppendKey,
type FieldPick,
} from "./mapping-fields";
/**
* One level of a captured payload, with every key and every leaf clickable, so
@@ -13,27 +18,36 @@ import { fieldTypeFromValue, pathAppendIndex, pathAppendKey, type FieldPick } fr
* A key is clickable in its own right: binding `data` whole is a legitimate
* choice, and the type is inferred from whatever that node happens to hold.
*/
const props = withDefaults(defineProps<{ value: unknown; path?: string; name?: string }>(), { path: "", name: "" });
const props = withDefaults(
defineProps<{ value: unknown; path?: string; name?: string }>(),
{ path: "", name: "" },
);
const emit = defineEmits<{ pick: [pick: FieldPick] }>();
const isBranch = computed(() => props.value !== null && typeof props.value === "object");
const isBranch = computed(
() => props.value !== null && typeof props.value === "object",
);
/** This level's children, each with the path that addresses it. */
const entries = computed<Array<{ key: string; value: unknown; path: string }>>(() => {
if (!isBranch.value) return [];
if (Array.isArray(props.value)) {
return props.value.map((child, index) => ({
key: String(index),
value: child,
path: pathAppendIndex(props.path, index),
}));
}
return Object.entries(props.value as Record<string, unknown>).map(([key, child]) => ({
key,
value: child,
path: pathAppendKey(props.path, key),
}));
});
const entries = computed<Array<{ key: string; value: unknown; path: string }>>(
() => {
if (!isBranch.value) return [];
if (Array.isArray(props.value)) {
return props.value.map((child, index) => ({
key: String(index),
value: child,
path: pathAppendIndex(props.path, index),
}));
}
return Object.entries(props.value as Record<string, unknown>).map(
([key, child]) => ({
key,
value: child,
path: pathAppendKey(props.path, key),
}),
);
},
);
function pick(path: string, key: string, value: unknown): void {
emit("pick", { path, type: fieldTypeFromValue(value), name: key });
@@ -41,7 +55,10 @@ function pick(path: string, key: string, value: unknown): void {
</script>
<template>
<ul v-if="isBranch" class="flex list-none flex-col gap-0.5 pl-4 font-mono text-xs">
<ul
v-if="isBranch"
class="flex list-none flex-col gap-0.5 pl-4 font-mono text-xs"
>
<li v-for="entry in entries" :key="entry.path">
<button
type="button"
@@ -50,7 +67,12 @@ function pick(path: string, key: string, value: unknown): void {
>
{{ entry.key }}
</button>
<PayloadTree :value="entry.value" :path="entry.path" :name="entry.key" @pick="emit('pick', $event)" />
<PayloadTree
:value="entry.value"
:path="entry.path"
:name="entry.key"
@pick="emit('pick', $event)"
/>
</li>
</ul>
+13 -3
View File
@@ -5,9 +5,17 @@
*/
/** The JSON shapes a bound field can claim, matching mapping.FieldType in Go. */
export type FieldType = "string" | "number" | "bool" | "object" | "array" | "any";
export type FieldType =
"string" | "number" | "bool" | "object" | "array" | "any";
export const FIELD_TYPES: FieldType[] = ["string", "number", "bool", "object", "array", "any"];
export const FIELD_TYPES: FieldType[] = [
"string",
"number",
"bool",
"object",
"array",
"any",
];
const FIELD_TYPE_SET: ReadonlySet<string> = new Set(FIELD_TYPES);
@@ -42,7 +50,9 @@ export function fieldTypeFromValue(value: unknown): FieldType {
/** Narrows a control's value back to a FieldType, refusing anything else. */
export function asFieldType(value: unknown): FieldType {
return typeof value === "string" && FIELD_TYPE_SET.has(value) ? (value as FieldType) : "any";
return typeof value === "string" && FIELD_TYPE_SET.has(value)
? (value as FieldType)
: "any";
}
export function pathAppendKey(path: string, key: string): string {
+24 -6
View File
@@ -2,7 +2,11 @@ import { ref } from "vue";
import { api, classifyActionError, type ActionErrorKind } from "@/lib/api";
import type { EventType } from "@/captures/event-types";
import { uniqueFieldName, type FieldPick, type FieldType } from "./mapping-fields";
import {
uniqueFieldName,
type FieldPick,
type FieldType,
} from "./mapping-fields";
/**
* The mappings page's shared state: the saved mappings, the captured events a
@@ -135,7 +139,9 @@ export async function loadMappings(): Promise<void> {
// picker instead of taking the mappings list down with it.
const [listed, captured, types] = await Promise.all([
api.mappings<{ mappings?: Mapping[] }>(),
api.captures<{ captures?: Capture[]; enabled?: boolean }>(100).catch(() => null),
api
.captures<{ captures?: Capture[]; enabled?: boolean }>(100)
.catch(() => null),
api.eventTypes<{ event_types?: EventType[] }>().catch(() => null),
]);
mappings.value = listed.mappings || [];
@@ -181,7 +187,8 @@ export function closeEditor(): void {
* that rather than as a payload whose paths all failed.
*/
export function selectCapture(value: string): void {
const capture = captures.value.find((candidate) => String(candidate.id) === value) ?? null;
const capture =
captures.value.find((candidate) => String(candidate.id) === value) ?? null;
const current = draft.value;
current.captureId = capture ? capture.id : null;
current.preview = null;
@@ -206,7 +213,12 @@ export function addField(pick: FieldPick): void {
current.fields.map((field) => field.name),
pick.name,
);
current.fields.push({ name, path: pick.path, type: pick.type, required: true });
current.fields.push({
name,
path: pick.path,
type: pick.type,
required: true,
});
// Any edit invalidates the preview: it described the fields as they were.
current.preview = null;
}
@@ -225,11 +237,17 @@ export function removeField(index: number): void {
export async function runPreview(): Promise<void> {
const current = draft.value;
if (current.captureId === null) {
actionError.value = { kind: "incomplete", message: "Pick a captured event to preview against." };
actionError.value = {
kind: "incomplete",
message: "Pick a captured event to preview against.",
};
return;
}
try {
current.preview = await api.mappingPreview<Preview>(current.captureId, current.fields);
current.preview = await api.mappingPreview<Preview>(
current.captureId,
current.fields,
);
actionError.value = null;
} catch (err) {
actionError.value = classifyActionError(err);