- 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
47 lines
1.6 KiB
JavaScript
47 lines
1.6 KiB
JavaScript
import { SchemaError } from '../errors.js';
|
|
import { schemaInfo } from './schemaInfo.js';
|
|
import { assertSchema } from '../utils.js';
|
|
export function schemaShape(schema, path = []) {
|
|
const output = _schemaShape(schema, path);
|
|
if (!output)
|
|
throw new SchemaError('No shape could be created for schema.', path);
|
|
return output;
|
|
}
|
|
function _schemaShape(schema, path) {
|
|
assertSchema(schema, path);
|
|
const info = schemaInfo(schema, false, path);
|
|
if (info.array || info.union) {
|
|
const arr = info.array || [];
|
|
const union = info.union || [];
|
|
return arr.concat(union).reduce((shape, next) => {
|
|
const nextShape = _schemaShape(next, path);
|
|
if (nextShape)
|
|
shape = { ...(shape ?? {}), ...nextShape };
|
|
return shape;
|
|
}, arr.length ? {} : undefined);
|
|
}
|
|
if (info.properties) {
|
|
const output = {};
|
|
for (const [key, prop] of Object.entries(info.properties)) {
|
|
const shape = _schemaShape(prop, [...path, key]);
|
|
if (shape)
|
|
output[key] = shape;
|
|
}
|
|
return output;
|
|
}
|
|
return info.types.includes('array') || info.types.includes('object') ? {} : undefined;
|
|
}
|
|
export function shapeFromObject(obj) {
|
|
let output = {};
|
|
const isArray = Array.isArray(obj);
|
|
for (const [key, value] of Object.entries(obj)) {
|
|
if (!value || typeof value !== 'object')
|
|
continue;
|
|
if (isArray)
|
|
output = { ...output, ...shapeFromObject(value) };
|
|
else
|
|
output[key] = shapeFromObject(value);
|
|
}
|
|
return output;
|
|
}
|