UNPKG

type-compiler

Version:

A TypeScript compiler plugin for enhanced runtime type checking and analysis with Zod validation

115 lines (114 loc) 2.9 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.UserServiceSchema = exports.UserRoleSchema = exports.TestUserSchema = exports.UserService = void 0; exports.validateSelfTest = validateSelfTest; const zod_1 = require("zod"); /** * A class with methods for testing class validation */ class UserService { constructor(apiKey, timeout = 3000) { this.apiKey = apiKey; this.timeout = timeout; } async getUser(id) { console.log(`Getting user with ID ${id}`); return { id, name: 'Test User', email: 'test@example.com', isActive: true, createdAt: new Date(), roles: ['viewer'] }; } updateUser(id, data) { console.log(`Updating user with ID ${id}`, data); return true; } } exports.UserService = UserService; /** * Check if the Zod schemas were generated correctly */ function validateSelfTest() { try { // In a real implementation, we would import and use the generated schemas: // import { zTestUser, zUserRole, zUserServiceConstructor } from './self-test'; // const user = zTestUser.parse({...}); // const role = zUserRole.parse('admin'); // const [apiKey, timeout] = zUserServiceConstructor.parse(['key', 5000]); console.log('Self-test validation would check the generated schemas here'); return true; } catch (error) { console.error('Self-test validation failed:', error); return false; } } exports.TestUserSchema = z.object({ id: z.any(), name: z.any(), email: z.any(), isActive: z.any(), createdAt: z.any(), roles: z.any(), metadata: z.any() }); exports.UserRoleSchema = z.object({ toString: z.any(), charAt: z.any(), charCodeAt: z.any(), concat: z.any(), indexOf: z.any(), lastIndexOf: z.any(), localeCompare: z.any(), match: z.any(), replace: z.any(), search: z.any(), slice: z.any(), split: z.any(), substring: z.any(), toLowerCase: z.any(), toLocaleLowerCase: z.any(), toUpperCase: z.any(), toLocaleUpperCase: z.any(), trim: z.any(), length: z.any(), substr: z.any(), valueOf: z.any(), codePointAt: z.any(), includes: z.any(), endsWith: z.any(), normalize: z.any(), repeat: z.any(), startsWith: z.any(), anchor: z.any(), big: z.any(), blink: z.any(), bold: z.any(), fixed: z.any(), fontcolor: z.any(), fontsize: z.any(), italics: z.any(), link: z.any(), small: z.any(), strike: z.any(), sub: z.any(), sup: z.any(), padStart: z.any(), padEnd: z.any(), trimEnd: z.any(), trimStart: z.any(), trimLeft: z.any(), trimRight: z.any(), matchAll: z.any(), __@iterator@54: z.any(), at: z.any() }); exports.UserServiceSchema = z.object({ apiKey: z.any(), timeout: z.any(), getUser: z.any(), updateUser: z.any() });