Skip to content

Commit

Permalink
Merge pull request #739 from samchon/features/invalid
Browse files Browse the repository at this point in the history
Make swagger file lighten for LLM reason + invalid path checking
  • Loading branch information
samchon authored Jan 10, 2024
2 parents 52254fb + 0922659 commit 9b87b19
Show file tree
Hide file tree
Showing 106 changed files with 708 additions and 1,311 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:

- name: test
working-directory: ./test
run: npm run start
run: npm start

- name: migrate
working-directory: ./packages/migrate
Expand Down
2 changes: 1 addition & 1 deletion benchmark/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"homepage": "https://nestia.io",
"dependencies": {
"@nestia/core": "^2.4.3",
"typia": "^5.3.5"
"typia": "^5.3.9"
},
"devDependencies": {
"@types/autocannon": "^7.9.0",
Expand Down
153 changes: 74 additions & 79 deletions deploy/publish.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,99 +5,94 @@ const path = require("path");
const packages = ["fetcher", "core", "sdk"];

const execute =
(cwd, stdio = "ignore") =>
(command) => {
console.log(command);
cp.execSync(command, { cwd, stdio });
};
(cwd, stdio = "ignore") =>
(command) => {
console.log(command);
cp.execSync(command, { cwd, stdio });
};

const setup = (tag) => (version) => (directory) => {
// CHANGE PACKAGE.JSON INFO
const file = `${directory}/package.json`;
const info = JSON.parse(fs.readFileSync(file, "utf8"));
info.version = version;
// CHANGE PACKAGE.JSON INFO
const file = `${directory}/package.json`;
const info = JSON.parse(fs.readFileSync(file, "utf8"));
info.version = version;

for (const record of [info.dependencies ?? {}, info.devDependencies ?? {}])
for (const key of Object.keys(record))
if (
key.startsWith("@nestia") &&
packages.includes(key.replace("@nestia/", ""))
) {
if (
tag === "tgz" &&
fs.existsSync(`${directory}/node_modules/${key}`)
)
try {
execute(directory)(`npm uninstall ${key}`);
} catch {}
record[key] =
tag === "tgz"
? path.resolve(
`${__dirname}/../packages/${key.replace(
"@nestia/",
"",
)}/nestia-${key.replace(
"@nestia/",
"",
)}-${version}.tgz`,
)
: `^${version}`;
}
for (const key of Object.keys(info.peerDependencies ?? {}))
if (
key.startsWith("@nestia") &&
packages.includes(key.replace("@nestia/", ""))
)
info.peerDependencies[key] = `>=${version}`;
for (const record of [info.dependencies ?? {}, info.devDependencies ?? {}])
for (const key of Object.keys(record))
if (
key.startsWith("@nestia") &&
packages.includes(key.replace("@nestia/", ""))
) {
if (tag === "tgz" && fs.existsSync(`${directory}/node_modules/${key}`))
try {
execute(directory)(`npm uninstall ${key}`);
} catch {}
record[key] =
tag === "tgz"
? path.resolve(
`${__dirname}/../packages/${key.replace(
"@nestia/",
"",
)}/nestia-${key.replace("@nestia/", "")}-${version}.tgz`,
)
: `^${version}`;
}
for (const key of Object.keys(info.peerDependencies ?? {}))
if (
key.startsWith("@nestia") &&
packages.includes(key.replace("@nestia/", ""))
)
info.peerDependencies[key] = `>=${version}`;

// SETUP UPDATED DEPENDENCIES
fs.writeFileSync(file, JSON.stringify(info, null, 2), "utf8");
execute(directory)("npm cache clean --force");
execute(directory)(`npm install`);
// SETUP UPDATED DEPENDENCIES
fs.writeFileSync(file, JSON.stringify(info, null, 2), "utf8");
execute(directory)("npm cache clean --force");
execute(directory)(`npm install`);
};

const deploy = (tag) => (version) => (name) => {
console.log("-----------------------------------------");
console.log(name.toUpperCase());
console.log("-----------------------------------------");
console.log("-----------------------------------------");
console.log(name.toUpperCase());
console.log("-----------------------------------------");

// SETUP
const directory = `${__dirname}/../packages/${name}`;
setup(tag)(version)(directory);
execute(directory)(`npm run build`);
// SETUP
const directory = `${__dirname}/../packages/${name}`;
setup(tag)(version)(directory);
execute(directory)(`npm run build`);

// PUBLISH (OR PACK)
if (tag === "tgz") execute(directory)(`npm pack`);
else execute(directory)(`npm publish --tag ${tag} --access public`);
console.log("");
// PUBLISH (OR PACK)
if (tag === "tgz") execute(directory)(`npm pack`);
else execute(directory)(`npm publish --tag ${tag} --access public`);
console.log("");
};

const publish = (tag) => (version) => {
// VALIDATE TAG
const dev = version.includes("-dev.") === true;
if (tag !== "latest" && dev === false)
throw new Error(`${tag} tag can only be used for dev versions.`);
else if (tag === "latest" && dev === true)
throw new Error(`latest tag can only be used for non-dev versions.`);
const publish = (tag) => async (version) => {
// VALIDATE TAG
const dev = version.includes("-dev.") === true;
if (tag !== "latest" && dev === false)
throw new Error(`${tag} tag can only be used for dev versions.`);
else if (tag === "latest" && dev === true)
throw new Error(`latest tag can only be used for non-dev versions.`);

// DO DEPLOY
const skip = (() => {
const index = process.argv.indexOf("--skip");
if (index === -1) return [];
// DO DEPLOY
const skip = (() => {
const index = process.argv.indexOf("--skip");
if (index === -1) return [];

const targets = process.argv.slice(index + 1);
return targets.filter((t) => packages.includes(t));
})();
for (const pack of packages) {
if (skip.includes(pack)) continue;
deploy(tag)(version)(pack);
}
const targets = process.argv.slice(index + 1);
return targets.filter((t) => packages.includes(t));
})();
for (const pack of packages) {
if (skip.includes(pack)) continue;
deploy(tag)(version)(pack);
await new Promise(resolve => setTimeout(resolve, 1_000));
}

// SETUP INTO TEST
console.log("-----------------------------------------");
console.log("TEST");
console.log("-----------------------------------------");
setup(tag)(version)(`${__dirname}/../test`);
// SETUP INTO TEST
console.log("-----------------------------------------");
console.log("TEST");
console.log("-----------------------------------------");
setup(tag)(version)(`${__dirname}/../test`);
};

module.exports = { publish };
10 changes: 5 additions & 5 deletions packages/core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@nestia/core",
"version": "0.0.0-dev.20991231",
"version": "2.4.4",
"description": "Super-fast validation decorators of NestJS",
"main": "lib/index.js",
"typings": "lib/index.d.ts",
Expand Down Expand Up @@ -38,7 +38,7 @@
},
"homepage": "https://nestia.io",
"dependencies": {
"@nestia/fetcher": "D:\\github\\samchon\\nestia\\packages\\fetcher\\nestia-fetcher-0.0.0-dev.20991231.tgz",
"@nestia/fetcher": "^2.4.4",
"@nestjs/common": ">=7.0.1",
"@nestjs/core": ">=7.0.1",
"@nestjs/platform-express": ">=7.0.1",
Expand All @@ -48,10 +48,10 @@
"raw-body": ">=2.0.0",
"reflect-metadata": ">=0.1.12",
"rxjs": ">=6.0.0",
"typia": "^5.3.4"
"typia": "^5.3.9"
},
"peerDependencies": {
"@nestia/fetcher": ">=0.0.0-dev.20991231",
"@nestia/fetcher": ">=2.4.4",
"@nestjs/common": ">=7.0.1",
"@nestjs/core": ">=7.0.1",
"@nestjs/platform-express": ">=7.0.1",
Expand All @@ -60,7 +60,7 @@
"reflect-metadata": ">=0.1.12",
"rxjs": ">=6.0.0",
"typescript": ">=4.8.0 <5.4.0",
"typia": ">=5.3.4 <6.0.0"
"typia": ">=5.3.9 <6.0.0"
},
"devDependencies": {
"@types/express": "^4.17.15",
Expand Down
2 changes: 1 addition & 1 deletion packages/e2e/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"ts-node": "^10.9.1",
"ts-patch": "^3.1.0",
"typescript": "^5.3.2",
"typia": "^5.3.4"
"typia": "^5.3.9"
},
"dependencies": {
"chalk": "^4.1.2",
Expand Down
2 changes: 1 addition & 1 deletion packages/fetcher/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@nestia/fetcher",
"version": "0.0.0-dev.20991231",
"version": "2.4.4",
"description": "Fetcher library of Nestia SDK",
"main": "lib/index.js",
"typings": "lib/index.d.ts",
Expand Down
2 changes: 1 addition & 1 deletion packages/migrate/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
"typescript-transform-paths": "^3.4.6"
},
"dependencies": {
"typia": "^5.3.4"
"typia": "^5.3.9"
},
"files": [
"lib",
Expand Down
10 changes: 5 additions & 5 deletions packages/sdk/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@nestia/sdk",
"version": "0.0.0-dev.20991231",
"version": "2.4.4",
"description": "Nestia SDK and Swagger generator",
"main": "lib/index.js",
"typings": "lib/index.d.ts",
Expand Down Expand Up @@ -34,7 +34,7 @@
},
"homepage": "https://nestia.io",
"dependencies": {
"@nestia/fetcher": "D:\\github\\samchon\\nestia\\packages\\fetcher\\nestia-fetcher-0.0.0-dev.20991231.tgz",
"@nestia/fetcher": "^2.4.4",
"cli": "^1.0.1",
"get-function-location": "^2.0.0",
"glob": "^7.2.0",
Expand All @@ -43,16 +43,16 @@
"tsconfck": "^2.0.1",
"tsconfig-paths": "^4.1.1",
"tstl": "^2.5.13",
"typia": "^5.3.4"
"typia": "^5.3.9"
},
"peerDependencies": {
"@nestia/fetcher": ">=0.0.0-dev.20991231",
"@nestia/fetcher": ">=2.4.4",
"@nestjs/common": ">=7.0.1",
"@nestjs/core": ">=7.0.1",
"reflect-metadata": ">=0.1.12",
"ts-node": ">=10.6.0",
"typescript": ">=4.8.0 <5.4.0",
"typia": ">=5.3.4 <6.0.0"
"typia": ">=5.3.9 <6.0.0"
},
"devDependencies": {
"@nestia/e2e": "^0.3.7",
Expand Down
14 changes: 14 additions & 0 deletions packages/sdk/src/INestiaConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,20 @@ export namespace INestiaConfig {
*/
beautify?: boolean | number;

/**
* Whether to include additional information or not.
*
* If configured to be `true`, those properties would be added into each
* API endpoinnt.
*
* - `x-nestia-method`
* - `x-nestia-namespace`
* ` `x-nestia-jsDocTags`
*
* @default false
*/
additional?: boolean;

/**
* API information.
*
Expand Down
13 changes: 12 additions & 1 deletion packages/sdk/src/analyses/ControllerAnalyzer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -274,9 +274,20 @@ export namespace ControllerAnalyzer {
}),
)
.flat()
.filter((path) => {
const escaped: string | null = PathAnalyzer.escape(path);
if (escaped === null)
project.errors.push({
file: controller.file,
controller: controller.name,
function: func.name,
message: `unable to escape the path "${path}".`,
});
return escaped !== null;
})
.map((path) => ({
...common,
path: PathAnalyzer.escape(path, () => "ControllerAnalyzer.analyze()"),
path: PathAnalyzer.escape(path)!,
accessors: [...PathUtil.accessors(path), func.name],
}));
};
Expand Down
Loading

0 comments on commit 9b87b19

Please sign in to comment.