-
-
Notifications
You must be signed in to change notification settings - Fork 105
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #853 from samchon/features/esm.sh
Adapt `tstl@v3` update.
- Loading branch information
Showing
32 changed files
with
1,230 additions
and
1,246 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(""); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}); |
Oops, something went wrong.