shared: schema: split enums from schemas

Otherwise zod will be included in client dependency graph and
increase the bundle size by 10kB unnecessarily.
This commit is contained in:
Jesse Chan
2020-10-28 12:06:14 +08:00
parent 20a1c2a75b
commit 9e03d2a385
14 changed files with 72 additions and 68 deletions
+6 -5
View File
@@ -1,12 +1,13 @@
import * as z from 'zod';
import type {infer as zodInfer} from 'zod';
import {AccessLevel, credentialsSchema} from '../Auth';
import {AccessLevel} from '../constants/Auth';
import {credentialsSchema} from '../Auth';
// All auth requests are schema validated to ensure security.
// POST /api/auth/authenticate
export const authAuthenticationSchema = credentialsSchema.pick({username: true, password: true});
export type AuthAuthenticationOptions = Required<z.infer<typeof authAuthenticationSchema>>;
export type AuthAuthenticationOptions = Required<zodInfer<typeof authAuthenticationSchema>>;
// POST /api/auth/authenticate - success response
export interface AuthAuthenticationResponse {
@@ -17,11 +18,11 @@ export interface AuthAuthenticationResponse {
// POST /api/auth/register
export const authRegistrationSchema = credentialsSchema;
export type AuthRegistrationOptions = Required<z.infer<typeof authRegistrationSchema>>;
export type AuthRegistrationOptions = Required<zodInfer<typeof authRegistrationSchema>>;
// PATCH /api/auth/users/{username}
export const authUpdateUserSchema = credentialsSchema.partial();
export type AuthUpdateUserOptions = z.infer<typeof authUpdateUserSchema>;
export type AuthUpdateUserOptions = zodInfer<typeof authUpdateUserSchema>;
// GET /api/auth/verify - preload configurations
export interface AuthVerificationPreloadConfigs {