- Delete old Vite+Svelte frontend - Initialize new SvelteKit project with TypeScript - Configure Tailwind CSS v4 + DaisyUI - Implement JWT authentication with auto-refresh - Create login page with form validation (Zod) - Add protected route guards - Update Docker configuration for single-stage build - Add E2E tests with Playwright (6/11 passing) - Fix Svelte 5 reactivity with $state() runes Known issues: - 5 E2E tests failing (timing/async issues) - Token refresh implementation needs debugging - Validation error display timing
25 lines
1.1 KiB
JavaScript
25 lines
1.1 KiB
JavaScript
import { append } from "./arrays.js";
|
|
export const flatMorph = (o, flatMapEntry) => {
|
|
const result = {};
|
|
const inputIsArray = Array.isArray(o);
|
|
let outputShouldBeArray = false;
|
|
for (const [i, entry] of Object.entries(o).entries()) {
|
|
const mapped = inputIsArray ? flatMapEntry(i, entry[1]) : flatMapEntry(...entry, i);
|
|
outputShouldBeArray ||= typeof mapped[0] === "number";
|
|
const flattenedEntries = Array.isArray(mapped[0]) || mapped.length === 0 ?
|
|
// if we have an empty array (for filtering) or an array with
|
|
// another array as its first element, treat it as a list
|
|
mapped
|
|
// otherwise, it should be a single entry, so nest it in a tuple
|
|
// so it doesn't get spread when the result is flattened
|
|
: [mapped];
|
|
for (const [k, v] of flattenedEntries) {
|
|
if (typeof k === "object")
|
|
result[k.group] = append(result[k.group], v);
|
|
else
|
|
result[k] = v;
|
|
}
|
|
}
|
|
return outputShouldBeArray ? Object.values(result) : result;
|
|
};
|