Skip to content

Commit

Permalink
progress check-in
Browse files Browse the repository at this point in the history
  • Loading branch information
asarazan committed Apr 29, 2024
1 parent ccb7580 commit e3886c4
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 9 deletions.
24 changes: 19 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 5 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"test": "jest",
"special": "ts-node src/index.ts '../../personal/Tangent-Mobile/api/entities/*.d.ts' -i -t -o ./schema/Tangent",
"special2": "ts-node src/index.ts 'tests/comparisons/**/*.d.ts' -i -t -o ./schema/Tests/",
"zod": "ts-node src/index.ts 'tests/comparisons/single/zodStuff.ts' -i -t -o ./schema/Tests/ZodStuff.kt",
"lint": "eslint . --ext .ts"
},
"author": "[email protected]",
Expand All @@ -31,15 +32,16 @@
"nodemon": "^2.0.19",
"prettier": "^2.4.1",
"ts-jest": "^27.0.7",
"ts-node": "^10.4.0"
"ts-node": "^10.4.0",
"zod": "^3.23.4"
},
"dependencies": {
"@typescript/vfs": "^1.4.0",
"glob": "^7.2.0",
"indent-string": "^4.0.0",
"lodash": "^4.17.21",
"promisify": "^0.0.3",
"yargs": "^17.2.1",
"typescript": "^4.4.4"
"typescript": "^4.4.4",
"yargs": "^17.2.1"
}
}
8 changes: 7 additions & 1 deletion src/martok/Martok.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,14 @@ import { processSnakeCase } from "./processing/SnakeCase";
import { processOldNames, sanitizeName } from "./processing/SanitizeNames";
import { TypeExpander } from "./processing/TypeExpander";
import { TsCompiler } from "./TsCompiler";
import { ZodProcessor } from "./processing/ZodProcessor";

type MartokState = {
nameScope: string[];
externalStatements: ts.Symbol[];
additionalDeclarations: string[];
typeReplacer: TypeReplacer;
zodProcessor: ZodProcessor;
};

export class Martok {
Expand All @@ -52,6 +54,9 @@ export class Martok {
public get typeReplacer(): TypeReplacer {
return this.storage.getStore()!.typeReplacer;
}
public get zodProcessor(): ZodProcessor {
return this.storage.getStore()!.zodProcessor;
}

private readonly storage;
private readonly formatter;
Expand Down Expand Up @@ -116,6 +121,7 @@ export class Martok {
externalStatements: [],
additionalDeclarations: [],
typeReplacer: new TypeReplacer(this),
zodProcessor: new ZodProcessor(this),
};
return this.storage.run(state, () => {
const result = _(this.config.files)
Expand Down Expand Up @@ -195,7 +201,7 @@ export class Martok {
let relativePath = path.resolve(path.dirname(file.fileName));
if (relativePath.startsWith(this.config.sourceRoot)) {
relativePath = relativePath.slice(this.config.sourceRoot.length);
} else {
} else if (!this.zodProcessor.isZodImport(file)) {
throw new Error(
`${file.fileName} is not within the given source root, it can't be included in this project.`
);
Expand Down
14 changes: 14 additions & 0 deletions src/martok/processing/ZodProcessor.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import ts 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 isZodDeclaration(): boolean {

Check warning on line 11 in src/martok/processing/ZodProcessor.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🕹️ Function is not covered

Warning! Not covered function
return true;

Check warning on line 12 in src/martok/processing/ZodProcessor.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement
}
}
9 changes: 9 additions & 0 deletions tests/comparisons/single/zodStuff.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { z } from "zod";

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(),
});

0 comments on commit e3886c4

Please sign in to comment.