-
-
Notifications
You must be signed in to change notification settings - Fork 102
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 #1164 from samchon/feat/human
New decorator `@HumanRoute()`.
- Loading branch information
Showing
24 changed files
with
558 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { SwaggerCustomizer } from "./SwaggerCustomizer"; | ||
|
||
/** | ||
* Human only API marking. | ||
* | ||
* This decorator marks the API for human only, so that LLM function calling | ||
* schema composer (of [`@samchon/openapi`](https://github.com/samchon/openapi)) | ||
* excludes the API. | ||
* | ||
* In other words, if you adjust the `@HumanRoute()` decorator to the API, | ||
* the API never participates in the LLM function calling. When calling the | ||
* {@link HttpLlm.application} function, matched {@link IHttpLlmFunction} data | ||
* never be composed. | ||
* | ||
* @returns Method decorator | ||
* @author Jeongho Nam - https://github.com/samchon | ||
*/ | ||
export function HumanRoute(): MethodDecorator { | ||
return SwaggerCustomizer((props) => { | ||
props.route["x-samchon-human"] = true; | ||
}); | ||
} |
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 |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { INestiaConfig } from "@nestia/sdk"; | ||
|
||
export const NESTIA_CONFIG: INestiaConfig = { | ||
input: ["src/controllers"], | ||
output: "src/api", | ||
e2e: "src/test", | ||
swagger: { | ||
output: "swagger.json", | ||
security: { | ||
bearer: { | ||
type: "apiKey", | ||
}, | ||
}, | ||
}, | ||
}; | ||
export default NESTIA_CONFIG; |
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 |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import core from "@nestia/core"; | ||
import { INestApplication } from "@nestjs/common"; | ||
import { NestFactory } from "@nestjs/core"; | ||
|
||
export class Backend { | ||
private application_?: INestApplication; | ||
|
||
public async open(): Promise<void> { | ||
this.application_ = await NestFactory.create( | ||
await core.EncryptedModule.dynamic(__dirname + "/controllers", { | ||
key: "A".repeat(32), | ||
iv: "B".repeat(16), | ||
}), | ||
{ logger: false }, | ||
); | ||
await this.application_.listen(37_000); | ||
} | ||
|
||
public async close(): Promise<void> { | ||
if (this.application_ === undefined) return; | ||
|
||
const app = this.application_; | ||
await app.close(); | ||
|
||
delete this.application_; | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
export { HttpError } from "@nestia/fetcher"; |
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
export type { IConnection } from "@nestia/fetcher"; |
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
export type { Primitive } from "typia"; |
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
export type { Resolved } from "typia"; |
35 changes: 35 additions & 0 deletions
35
test/features/route-human/src/api/functional/health/index.ts
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 |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/** | ||
* @packageDocumentation | ||
* @module api.functional.health | ||
* @nestia Generated by Nestia - https://github.com/samchon/nestia | ||
*/ | ||
//================================================================ | ||
import type { IConnection } from "@nestia/fetcher"; | ||
import { PlainFetcher } from "@nestia/fetcher/lib/PlainFetcher"; | ||
|
||
/** | ||
* @controller HealthController.get | ||
* @path GET /health | ||
* @nestia Generated by Nestia - https://github.com/samchon/nestia | ||
*/ | ||
export async function get(connection: IConnection): Promise<void> { | ||
return PlainFetcher.fetch(connection, { | ||
...get.METADATA, | ||
template: get.METADATA.path, | ||
path: get.path(), | ||
}); | ||
} | ||
export namespace get { | ||
export const METADATA = { | ||
method: "GET", | ||
path: "/health", | ||
request: null, | ||
response: { | ||
type: "application/json", | ||
encrypted: false, | ||
}, | ||
status: 200, | ||
} as const; | ||
|
||
export const path = () => "/health"; | ||
} |
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 |
---|---|---|
@@ -0,0 +1,9 @@ | ||
/** | ||
* @packageDocumentation | ||
* @module api.functional | ||
* @nestia Generated by Nestia - https://github.com/samchon/nestia | ||
*/ | ||
//================================================================ | ||
export * as health from "./health"; | ||
export * as performance from "./performance"; | ||
export * as route from "./route"; |
40 changes: 40 additions & 0 deletions
40
test/features/route-human/src/api/functional/performance/index.ts
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 |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/** | ||
* @packageDocumentation | ||
* @module api.functional.performance | ||
* @nestia Generated by Nestia - https://github.com/samchon/nestia | ||
*/ | ||
//================================================================ | ||
import type { IConnection } from "@nestia/fetcher"; | ||
import { PlainFetcher } from "@nestia/fetcher/lib/PlainFetcher"; | ||
import type { Primitive } from "typia"; | ||
|
||
import type { IPerformance } from "../../structures/IPerformance"; | ||
|
||
/** | ||
* @controller PerformanceController.get | ||
* @path GET /performance | ||
* @nestia Generated by Nestia - https://github.com/samchon/nestia | ||
*/ | ||
export async function get(connection: IConnection): Promise<get.Output> { | ||
return PlainFetcher.fetch(connection, { | ||
...get.METADATA, | ||
template: get.METADATA.path, | ||
path: get.path(), | ||
}); | ||
} | ||
export namespace get { | ||
export type Output = Primitive<IPerformance>; | ||
|
||
export const METADATA = { | ||
method: "GET", | ||
path: "/performance", | ||
request: null, | ||
response: { | ||
type: "application/json", | ||
encrypted: false, | ||
}, | ||
status: 200, | ||
} as const; | ||
|
||
export const path = () => "/performance"; | ||
} |
40 changes: 40 additions & 0 deletions
40
test/features/route-human/src/api/functional/route/index.ts
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 |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/** | ||
* @packageDocumentation | ||
* @module api.functional.route | ||
* @nestia Generated by Nestia - https://github.com/samchon/nestia | ||
*/ | ||
//================================================================ | ||
import type { IConnection } from "@nestia/fetcher"; | ||
import { PlainFetcher } from "@nestia/fetcher/lib/PlainFetcher"; | ||
import type { Primitive } from "typia"; | ||
|
||
import type { IBbsArticle } from "../../structures/IBbsArticle"; | ||
|
||
/** | ||
* @controller TypedRouteController.random | ||
* @path GET /route/random | ||
* @nestia Generated by Nestia - https://github.com/samchon/nestia | ||
*/ | ||
export async function random(connection: IConnection): Promise<random.Output> { | ||
return PlainFetcher.fetch(connection, { | ||
...random.METADATA, | ||
template: random.METADATA.path, | ||
path: random.path(), | ||
}); | ||
} | ||
export namespace random { | ||
export type Output = Primitive<IBbsArticle>; | ||
|
||
export const METADATA = { | ||
method: "GET", | ||
path: "/route/random", | ||
request: null, | ||
response: { | ||
type: "application/json", | ||
encrypted: false, | ||
}, | ||
status: 200, | ||
} as const; | ||
|
||
export const path = () => "/route/random"; | ||
} |
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 |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import * as api from "./module"; | ||
|
||
export * from "./module"; | ||
export default api; |
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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
export type * from "./IConnection"; | ||
export type * from "./Primitive"; | ||
export type * from "./Resolved"; | ||
export * from "./HttpError"; | ||
|
||
export * as functional from "./functional"; |
40 changes: 40 additions & 0 deletions
40
test/features/route-human/src/api/structures/IBbsArticle.ts
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 |
---|---|---|
@@ -0,0 +1,40 @@ | ||
export interface IBbsArticle { | ||
/** | ||
* @format uuid | ||
*/ | ||
id: string; | ||
|
||
/** | ||
* @minLength 3 | ||
* @maxLength 50 | ||
*/ | ||
title: string; | ||
|
||
body: string; | ||
|
||
files: IAttachmentFile[]; | ||
|
||
/** | ||
* @format date-time | ||
*/ | ||
created_at: string; | ||
} | ||
|
||
export interface IAttachmentFile { | ||
/** | ||
* @minLengt 1 | ||
* @maxLength 255 | ||
*/ | ||
name: string | null; | ||
|
||
/** | ||
* @minLength 1 | ||
* @maxLength 8 | ||
*/ | ||
extension: string | null; | ||
|
||
/** | ||
* @format uri | ||
*/ | ||
url: string; | ||
} |
10 changes: 10 additions & 0 deletions
10
test/features/route-human/src/api/structures/IPerformance.ts
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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
/** | ||
* Performance info. | ||
* | ||
* @author Samchon | ||
*/ | ||
export interface IPerformance { | ||
cpu: NodeJS.CpuUsage; | ||
memory: NodeJS.MemoryUsage; | ||
resource: NodeJS.ResourceUsage; | ||
} |
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 |
---|---|---|
@@ -0,0 +1,81 @@ | ||
/** | ||
* System Information. | ||
* | ||
* @author Jeongho Nam | ||
*/ | ||
export interface ISystem { | ||
/** | ||
* Random Unique ID. | ||
*/ | ||
uid: number; | ||
|
||
/** | ||
* `process.argv` | ||
*/ | ||
arguments: string[]; | ||
|
||
/** | ||
* Git commit info. | ||
*/ | ||
commit: ISystem.ICommit; | ||
|
||
/** | ||
* `package.json` | ||
*/ | ||
package: ISystem.IPackage; | ||
|
||
/** | ||
* Creation time of this server. | ||
*/ | ||
created_at: string; | ||
} | ||
|
||
export namespace ISystem { | ||
/** | ||
* Git commit info. | ||
*/ | ||
export interface ICommit { | ||
shortHash: string; | ||
branch: string; | ||
hash: string; | ||
subject: string; | ||
sanitizedSubject: string; | ||
body: string; | ||
author: ICommit.IUser; | ||
committer: ICommit.IUser; | ||
authored_at: string; | ||
commited_at: string; | ||
notes?: string; | ||
tags: string[]; | ||
} | ||
export namespace ICommit { | ||
/** | ||
* Git user account info. | ||
*/ | ||
export interface IUser { | ||
name: string; | ||
email: string; | ||
} | ||
} | ||
|
||
/** | ||
* NPM package info. | ||
*/ | ||
export interface IPackage { | ||
name: string; | ||
version: string; | ||
description: string; | ||
main?: string; | ||
typings?: string; | ||
scripts: Record<string, string>; | ||
repository: { type: "git"; url: string }; | ||
author: string; | ||
license: string; | ||
bugs: { url: string }; | ||
homepage: string; | ||
devDependencies?: Record<string, string>; | ||
dependencies: Record<string, string>; | ||
publishConfig?: { registry: string }; | ||
files?: string[]; | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
test/features/route-human/src/controllers/HealthController.ts
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 |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import core from "@nestia/core"; | ||
import { Controller } from "@nestjs/common"; | ||
|
||
@Controller("health") | ||
export class HealthController { | ||
@core.HumanRoute() | ||
@core.TypedRoute.Get() | ||
public get(): void {} | ||
} |
17 changes: 17 additions & 0 deletions
17
test/features/route-human/src/controllers/PerformanceController.ts
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 |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import core from "@nestia/core"; | ||
import { Controller } from "@nestjs/common"; | ||
|
||
import { IPerformance } from "@api/lib/structures/IPerformance"; | ||
|
||
@Controller("performance") | ||
export class PerformanceController { | ||
@core.HumanRoute() | ||
@core.TypedRoute.Get() | ||
public async get(): Promise<IPerformance> { | ||
return { | ||
cpu: process.cpuUsage(), | ||
memory: process.memoryUsage(), | ||
resource: process.resourceUsage(), | ||
}; | ||
} | ||
} |
Oops, something went wrong.