- 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
57 lines
1.8 KiB
JavaScript
57 lines
1.8 KiB
JavaScript
import { createAdapter } from './adapters.js';
|
|
import { splitPath } from '../stringPath.js';
|
|
import { memoize } from '../memoize.js';
|
|
import { convertSchema } from './yup-to-json-schema/index.js';
|
|
const modules = async () => {
|
|
const { ValidationError } = await import(/* webpackIgnore: true */ 'yup');
|
|
return { ValidationError };
|
|
};
|
|
const fetchModule = /* @__PURE__ */ memoize(modules);
|
|
/* @__NO_SIDE_EFFECTS__ */
|
|
export function yupToJSONSchema(schema) {
|
|
return convertSchema(schema, {
|
|
converters: {
|
|
date: (desc, options) => {
|
|
return options.string(desc, options);
|
|
}
|
|
}
|
|
});
|
|
}
|
|
async function validate(schema, data) {
|
|
const { ValidationError } = await fetchModule();
|
|
try {
|
|
return {
|
|
success: true,
|
|
data: await schema.validate(data, { strict: true, abortEarly: false })
|
|
};
|
|
}
|
|
catch (error) {
|
|
if (!(error instanceof ValidationError))
|
|
throw error;
|
|
return {
|
|
success: false,
|
|
issues: error.inner.map((error) => ({
|
|
message: error.message,
|
|
path: error.path !== null && error.path !== undefined ? splitPath(error.path) : undefined
|
|
}))
|
|
};
|
|
}
|
|
}
|
|
/* @__NO_SIDE_EFFECTS__ */
|
|
function _yup(schema, options) {
|
|
return createAdapter({
|
|
superFormValidationLibrary: 'yup',
|
|
validate: async (data) => validate(schema, data),
|
|
jsonSchema: options?.jsonSchema ?? yupToJSONSchema(schema),
|
|
defaults: options?.defaults
|
|
});
|
|
}
|
|
function _yupClient(schema) {
|
|
return {
|
|
superFormValidationLibrary: 'yup',
|
|
validate: async (data) => validate(schema, data)
|
|
};
|
|
}
|
|
export const yup = /* @__PURE__ */ memoize(_yup);
|
|
export const yupClient = /* @__PURE__ */ memoize(_yupClient);
|