Skip to content

Commit

Permalink
Merge pull request #853 from samchon/features/esm.sh
Browse files Browse the repository at this point in the history
Adapt `tstl@v3` update.
  • Loading branch information
samchon authored Mar 28, 2024
2 parents 90b59f9 + 6d7f7d8 commit 14eb680
Show file tree
Hide file tree
Showing 32 changed files with 1,230 additions and 1,246 deletions.
6 changes: 3 additions & 3 deletions benchmark/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
},
"homepage": "https://nestia.io",
"dependencies": {
"@nestia/core": "^2.4.3",
"@nestia/core": "^2.6.3",
"typia": "^5.5.7"
},
"devDependencies": {
Expand All @@ -41,10 +41,10 @@
"jsdom": "^22.0.0",
"physical-cpu-count": "^2.0.0",
"rimraf": "^5.0.1",
"tgrid": "^0.8.7",
"tgrid": "^0.10.0",
"ts-node": "^10.9.1",
"ts-patch": "^3.1.1",
"tstl": "^2.5.13",
"tstl": "^3.0.0",
"typescript": "^5.4.2"
}
}
115 changes: 57 additions & 58 deletions benchmark/src/generate/BenchmarkProgrammer.ts
Original file line number Diff line number Diff line change
@@ -1,69 +1,68 @@
import fs from "fs";

export namespace BenchmarkProgrammer {
export interface ICategory {
name: string;
libraries: ILibrary[];
features: string[];
}
export interface ILibrary {
name: string;
body: (input: string) => string;
}
export interface ICategory {
name: string;
libraries: ILibrary[];
features: string[];
}
export interface ILibrary {
name: string;
body: (input: string) => string;
}

export async function generate(
category: ICategory,
filter: (p: { library: string; feature: string }) => boolean = (p) =>
(p.library === "class-transformer" ||
p.library === "class-validator") &&
p.feature === "UltimateUnion",
): Promise<void> {
for (const library of category.libraries) {
const location: string = [
__dirname,
"..",
"programs",
emend(category.name),
emend(library.name),
].join("/");
export async function generate(
category: ICategory,
filter: (p: { library: string; feature: string }) => boolean = (p) =>
(p.library === "class-transformer" || p.library === "class-validator") &&
p.feature === "UltimateUnion",
): Promise<void> {
for (const library of category.libraries) {
const location: string = [
__dirname,
"..",
"programs",
emend(category.name),
emend(library.name),
].join("/");

try {
await fs.promises.mkdir(location);
} catch {}
for (const file of await fs.promises.readdir(location))
if (!file.includes("create"))
await fs.promises.rm(`${location}/${file}`);
try {
await fs.promises.mkdir(location);
} catch {}
for (const file of await fs.promises.readdir(location))
if (!file.includes("create"))
await fs.promises.rm(`${location}/${file}`);

for (const feature of category.features) {
if (
filter({
feature,
library: library.name,
})
)
continue;
for (const feature of category.features) {
if (
filter({
feature,
library: library.name,
})
)
continue;

const file: string = [
"benchmark",
emend(category.name.split("/")[0]),
emend(library.name),
feature,
].join("-");
const file: string = [
"benchmark",
emend(category.name.split("/")[0]),
emend(library.name),
feature,
].join("-");

await fs.promises.writeFile(
`${location}/${file}.ts`,
library.body(feature),
"utf8",
);
}
}
await fs.promises.writeFile(
`${location}/${file}.ts`,
library.body(feature),
"utf8",
);
}
}
}

export const emend = (name: string) =>
name.replaceAll("(", "").replaceAll(")", "").replaceAll(" ", "-");
export const pascal = (name: string) =>
name
.split("-")
.map((str) => str[0].toUpperCase() + str.slice(1))
.join("");
export const emend = (name: string) =>
name.replaceAll("(", "").replaceAll(")", "").replaceAll(" ", "-");
export const pascal = (name: string) =>
name
.split("-")
.map((str) => str[0].toUpperCase() + str.slice(1))
.join("");
}
204 changes: 102 additions & 102 deletions benchmark/src/generate/assert.ts
Original file line number Diff line number Diff line change
@@ -1,121 +1,121 @@
import { BenchmarkProgrammer } from "./BenchmarkProgrammer";

const FEATURES: string[] = [
"ObjectSimple",
"ObjectHierarchical",
"ObjectRecursive",
"ObjectUnionExplicit",
"ArraySimple",
"ArrayHierarchical",
"ArrayRecursive",
"ArrayRecursiveUnionExplicit",
"ObjectSimple",
"ObjectHierarchical",
"ObjectRecursive",
"ObjectUnionExplicit",
"ArraySimple",
"ArrayHierarchical",
"ArrayRecursive",
"ArrayRecursiveUnionExplicit",
];

const CLIENTS: BenchmarkProgrammer.ILibrary[] = [
"nestia (express)",
"nestia (fastify)",
"NestJS (express)",
"NestJS (fastify)",
"Fastify",
"nestia (express)",
"nestia (fastify)",
"NestJS (express)",
"NestJS (fastify)",
"Fastify",
].map((name) => ({
name,
body: (type: string) =>
[
`import { createAssertBenchmarkProgram } from "../createAssertBenchmarkProgram";`,
``,
`createAssertBenchmarkProgram(`,
` __dirname + "/../servers/${BenchmarkProgrammer.emend(
name,
)}/benchmark-assert-${BenchmarkProgrammer.emend(
name,
)}-${type}" + __filename.substr(-3)`,
`);`,
].join("\n"),
name,
body: (type: string) =>
[
`import { createAssertBenchmarkProgram } from "../createAssertBenchmarkProgram";`,
``,
`createAssertBenchmarkProgram(`,
` __dirname + "/../servers/${BenchmarkProgrammer.emend(
name,
)}/benchmark-assert-${BenchmarkProgrammer.emend(
name,
)}-${type}" + __filename.substr(-3)`,
`);`,
].join("\n"),
}));

const SERVERS: BenchmarkProgrammer.ILibrary[] = [
...["express", "fastify"].map((lib) => ({
name: `NestJS (${lib})`,
body: (type: string) => {
type = `ClassValidator${type}`;
const program: string = `createNest${lib[0].toUpperCase()}${lib.substring(
1,
)}AssertProgram`;
const port: string = lib === "express" ? `37_011` : `37_021`;
...["express", "fastify"].map((lib) => ({
name: `NestJS (${lib})`,
body: (type: string) => {
type = `ClassValidator${type}`;
const program: string = `createNest${lib[0].toUpperCase()}${lib.substring(
1,
)}AssertProgram`;
const port: string = lib === "express" ? `37_011` : `37_021`;

return [
`import { Body, Controller, Post } from "@nestjs/common";`,
``,
`import { ${type} } from "../../../../structures/class-validator/${type}";`,
`import { ${program} } from "../${program}";`,
``,
`${program}(true)(${port})(`,
` () => {`,
` @Controller()`,
` class NestJsController {`,
` @Post("assert")`,
` public assert(@Body() _input: ${type}): void {}`,
` }`,
` return NestJsController;`,
` },`,
`);`,
].join("\n");
},
})),
...["express", "fastify"].map((lib) => ({
name: `nestia (${lib})`,
body: (type: string) => {
const program: string = `createNest${lib[0].toUpperCase()}${lib.substring(
1,
)}AssertProgram`;
const port: string = lib === "express" ? `37_012` : `37_022`;
return [
`import { Body, Controller, Post } from "@nestjs/common";`,
``,
`import { ${type} } from "../../../../structures/class-validator/${type}";`,
`import { ${program} } from "../${program}";`,
``,
`${program}(true)(${port})(`,
` () => {`,
` @Controller()`,
` class NestJsController {`,
` @Post("assert")`,
` public assert(@Body() _input: ${type}): void {}`,
` }`,
` return NestJsController;`,
` },`,
`);`,
].join("\n");
},
})),
...["express", "fastify"].map((lib) => ({
name: `nestia (${lib})`,
body: (type: string) => {
const program: string = `createNest${lib[0].toUpperCase()}${lib.substring(
1,
)}AssertProgram`;
const port: string = lib === "express" ? `37_012` : `37_022`;

return [
`import { Controller, Post } from "@nestjs/common";`,
``,
`import core from "@nestia/core";`,
``,
`import { Collection } from "../../../../structures/pure/Collection";`,
`import { ${type} } from "../../../../structures/pure/${type}";`,
`import { ${program} } from "../${program}";`,
``,
`${program}(false)(${port})(() => {`,
` @Controller()`,
` class NestiaController {`,
` @Post("assert")`,
` public assert(@core.TypedBody() _input: Collection<${type}>): void {}`,
` }`,
` return NestiaController;`,
`});`,
].join("\n");
},
})),
{
name: "Fastify",
body: (type: string) => {
const program = "createAjvAssertProgram";
return [
`import typia from "typia";`,
``,
`import { Collection } from "../../../../structures/pure/Collection";`,
`import { ${type} } from "../../../../structures/pure/${type}";`,
`import { ${program} } from "../${program}";`,
``,
`${program}(37_002)(`,
` typia.json.application<[Collection<${type}>], "ajv">()`,
`);`,
].join("\n");
},
return [
`import { Controller, Post } from "@nestjs/common";`,
``,
`import core from "@nestia/core";`,
``,
`import { Collection } from "../../../../structures/pure/Collection";`,
`import { ${type} } from "../../../../structures/pure/${type}";`,
`import { ${program} } from "../${program}";`,
``,
`${program}(false)(${port})(() => {`,
` @Controller()`,
` class NestiaController {`,
` @Post("assert")`,
` public assert(@core.TypedBody() _input: Collection<${type}>): void {}`,
` }`,
` return NestiaController;`,
`});`,
].join("\n");
},
})),
{
name: "Fastify",
body: (type: string) => {
const program = "createAjvAssertProgram";
return [
`import typia from "typia";`,
``,
`import { Collection } from "../../../../structures/pure/Collection";`,
`import { ${type} } from "../../../../structures/pure/${type}";`,
`import { ${program} } from "../${program}";`,
``,
`${program}(37_002)(`,
` typia.json.application<[Collection<${type}>], "ajv">()`,
`);`,
].join("\n");
},
},
];

BenchmarkProgrammer.generate({
name: "assert",
features: FEATURES,
libraries: CLIENTS,
name: "assert",
features: FEATURES,
libraries: CLIENTS,
});
BenchmarkProgrammer.generate({
name: "assert/servers",
features: FEATURES,
libraries: SERVERS,
name: "assert/servers",
features: FEATURES,
libraries: SERVERS,
});
Loading

0 comments on commit 14eb680

Please sign in to comment.