-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,24 @@ | ||
import ts, { isVariableStatement } from "typescript"; | ||
import ts, { isVariableDeclaration, isVariableStatement } from "typescript"; | ||
import { Martok } from "../Martok"; | ||
|
||
export class ZodProcessor { | ||
public constructor(private martok: Martok) {} | ||
|
||
public isZodImport(file: ts.SourceFile): boolean { | ||
return file.fileName.includes("/martok/node_modules/zod/lib/"); | ||
public getType(statement: ts.Statement): ts.Type | undefined { | ||
if (!isVariableStatement(statement)) return undefined; | ||
try { | ||
const decl = statement.declarationList.declarations[0]; | ||
if (!isVariableDeclaration(decl)) return undefined; | ||
Check warning on line 11 in src/martok/processing/ZodProcessor.ts GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)🧾 Statement is not covered
Check warning on line 11 in src/martok/processing/ZodProcessor.ts GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)🧾 Statement is not covered
|
||
const type = this.martok.checker.getTypeAtLocation(decl); | ||
const symbol = type.aliasSymbol ?? type.symbol; | ||
Check warning on line 13 in src/martok/processing/ZodProcessor.ts GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)🧾 Statement is not covered
Check warning on line 13 in src/martok/processing/ZodProcessor.ts GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)🌿 Branch is not covered
Check warning on line 13 in src/martok/processing/ZodProcessor.ts GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)🌿 Branch is not covered
Check warning on line 13 in src/martok/processing/ZodProcessor.ts GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)🌿 Branch is not covered
|
||
return symbol.getEscapedName() === "ZodObject" ? type : undefined; | ||
Check warning on line 14 in src/martok/processing/ZodProcessor.ts GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)🧾 Statement is not covered
Check warning on line 14 in src/martok/processing/ZodProcessor.ts GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)🌿 Branch is not covered
|
||
} catch (e: unknown) { | ||
console.error(e); | ||
return undefined; | ||
} | ||
} | ||
|
||
public isZodStatement(node: ts.Node): boolean { | ||
return true; // TODO | ||
public shouldExpand(statement: ts.Statement) { | ||
return this.getType(statement) !== undefined; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,19 @@ | ||
import { z } from "zod"; | ||
|
||
const FormData = z.object({ | ||
export const FormData = z.object({ | ||
firstName: z.string().min(1).max(18), | ||
lastName: z.string().min(1).max(18), | ||
phone: z.string().min(10).max(14).optional(), | ||
email: z.string().email(), | ||
url: z.string().url().optional(), | ||
}); | ||
|
||
/** | ||
* @expand | ||
*/ | ||
export type FormDataType = typeof FormData.shape; | ||
|
||
/** | ||
* @expand | ||
*/ | ||
export type Inferred = z.infer<typeof FormData>; |