UNPKG

@autobe/compiler

Version:

AI backend server code generator

10 lines 25.3 kB
export const AutoBeCompilerTestTemplate: Record<string, string> = { "package.json": "{\n \"private\": true,\n \"name\": \"@ORGANIZATION/PROJECT\",\n \"version\": \"0.1.0\",\n \"description\": \"Starter kit of Nestia\",\n \"main\": \"lib/index.js\",\n \"scripts\": {\n \"benchmark\": \"node bin/test/benchmark\",\n \"test\": \"node bin/test\",\n \"test:webpack\": \"npm run webpack && node bin/test/webpack.js\",\n \"------------------------BUILDS------------------------\": \"\",\n \"build\": \"npm run build:prisma && npm run build:sdk && npm run build:main && npm run build:test\",\n \"build:api\": \"rimraf packages/api/lib && nestia all && rimraf packages/api/lib && tsc -p packages/api/tsconfig.json && rollup -c packages/api/rollup.config.js\",\n \"build:env\": \"ts-node build/env.ts\",\n \"build:main\": \"rimraf lib && tsc\",\n \"build:sdk\": \"rimraf src/api/functional && nestia sdk\",\n \"build:prisma\": \"prisma generate --schema prisma/schema\",\n \"build:swagger\": \"nestia swagger\",\n \"build:test\": \"rimraf bin && tsc -p test/tsconfig.json\",\n \"dev\": \"npm run build:test -- --watch\",\n \"eslint\": \"eslint src && eslint test\",\n \"eslint:fix\": \"eslint --fix src && eslint --fix test\",\n \"prepare\": \"ts-patch install && npm run build:env && npm run build:prisma\",\n \"prettier\": \"prettier src --write && prettier test --write\",\n \"------------------------WEBPACK------------------------\": \"\",\n \"webpack\": \"rimraf dist && webpack\",\n \"webpack:start\": \"cd dist && node dist/server\",\n \"webpack:test\": \"npm run webpack && node bin/test/webpack.js\",\n \"------------------------DEPLOYS------------------------\": \"\",\n \"package:api\": \"npm run build:api && cd packages/api && npm publish\",\n \"schema\": \"ts-node src/executable/schema\",\n \"start\": \"node lib/executable/server\",\n \"start:dev\": \"nest start --watch\",\n \"start:swagger\": \"ts-node src/executable/swagger.ts\"\n },\n \"repository\": {\n \"type\": \"git\",\n \"url\": \"https://github.com/samchon/nestia-start\"\n },\n \"keywords\": [\n \"nestia\",\n \"template\",\n \"boilerplate\"\n ],\n \"author\": \"AUTHOR\",\n \"license\": \"MIT\",\n \"bugs\": {\n \"url\": \"https://github.com/samchon/nestia-start/issues\"\n },\n \"homepage\": \"https://github.com/samchon/nestia-start#readme\",\n \"devDependencies\": {\n \"@nestia/benchmark\": \"^8.0.7\",\n \"@nestia/e2e\": \"^8.0.7\",\n \"@nestia/sdk\": \"^8.0.7\",\n \"@nestjs/cli\": \"^11.0.7\",\n \"@rollup/plugin-terser\": \"^0.4.4\",\n \"@rollup/plugin-typescript\": \"^11.1.6\",\n \"@trivago/prettier-plugin-sort-imports\": \"^4.3.0\",\n \"@types/bcryptjs\": \"^3.0.0\",\n \"@types/cli\": \"^0.11.21\",\n \"@types/cli-progress\": \"^3.11.5\",\n \"@types/express\": \"^4.17.21\",\n \"@types/inquirer\": \"^8.2.5\",\n \"@types/jsonwebtoken\": \"^9.0.5\",\n \"@types/node\": \"^18.11.0\",\n \"@types/uuid\": \"^8.3.4\",\n \"@typescript-eslint/eslint-plugin\": \"^8.1.0\",\n \"@typescript-eslint/parser\": \"^8.1.0\",\n \"chalk\": \"^4.1.2\",\n \"cli\": \"^1.0.1\",\n \"cli-progress\": \"^3.12.0\",\n \"copy-webpack-plugin\": \"^11.0.0\",\n \"eslint-plugin-deprecation\": \"^3.0.0\",\n \"express\": \"^4.18.2\",\n \"fastify\": \"^5.4.0\",\n \"nestia\": \"^8.0.7\",\n \"prettier\": \"^3.2.4\",\n \"prettier-plugin-prisma\": \"^5.0.0\",\n \"prisma-markdown\": \"^3.0.1\",\n \"rimraf\": \"^3.0.2\",\n \"rollup\": \"^4.18.0\",\n \"source-map-support\": \"^0.5.21\",\n \"swagger-ui-express\": \"^5.0.0\",\n \"ts-loader\": \"^9.5.1\",\n \"ts-node\": \"^10.9.1\",\n \"ts-patch\": \"^3.3.0\",\n \"typescript\": \"~5.9.2\",\n \"typescript-transform-paths\": \"^3.5.5\",\n \"webpack\": \"^5.89.0\",\n \"webpack-cli\": \"^5.1.4\",\n \"write-file-webpack-plugin\": \"^4.5.1\"\n },\n \"dependencies\": {\n \"@nestia/core\": \"^8.0.7\",\n \"@nestia/fetcher\": \"^8.0.7\",\n \"@nestjs/common\": \"^11.1.3\",\n \"@nestjs/core\": \"^11.1.3\",\n \"@nestjs/platform-express\": \"^11.1.3\",\n \"@nestjs/platform-fastify\": \"^11.1.3\",\n \"@prisma/adapter-pg\": \"^6.16.2\",\n \"@prisma/adapter-better-sqlite3\": \"^6.16.2\",\n \"@prisma/client\": \"^6.16.2\",\n \"bcryptjs\": \"^3.0.2\",\n \"commander\": \"10.0.0\",\n \"dotenv\": \"^16.3.1\",\n \"dotenv-expand\": \"^10.0.0\",\n \"inquirer\": \"8.2.5\",\n \"jsonwebtoken\": \"^9.0.2\",\n \"prisma\": \"^6.16.2\",\n \"serialize-error\": \"^4.1.0\",\n \"tgrid\": \"^1.1.0\",\n \"tstl\": \"^3.0.0\",\n \"typia\": \"^9.7.2\",\n \"uuid\": \"^9.0.0\"\n },\n \"pnpm\": {\n \"onlyBuiltDependencies\": [\"better-sqlite3\"]\n },\n \"stackblitz\": {\n \"startCommand\": \"npm run prepare && npm run build:test && npm run test -- --simultaneous 1\"\n }\n}\n", "src/executable/schema.ts": "import { MySetupWizard } from \"../setup/MySetupWizard\";\n\nconst main = async (): Promise<void> => {\n await MySetupWizard.schema();\n await MySetupWizard.seed();\n};\nmain().catch((error) => {\n console.error(error);\n process.exit(-1);\n});\n", "src/setup/MySetupWizard.ts": "export namespace MySetupWizard {\n export async function schema(): Promise<void> {\n console.log(\"Realize agent has not generated main program yet.\");\n }\n\n export async function seed(): Promise<void> {}\n}\n", "test/helpers/TestAutomation.ts": "import api from \"@ORGANIZATION/PROJECT-api\";\nimport { DynamicExecutor } from \"@nestia/e2e\";\nimport { sleep_for } from \"tstl\";\n\nimport { MyConfiguration } from \"../../src/MyConfiguration\";\nimport { MySetupWizard } from \"../../src/setup/MySetupWizard\";\n\nexport namespace TestAutomation {\n export interface IProps<T> {\n open(options: IOptions): Promise<T>;\n close(backend: T): Promise<void>;\n onComplete(exec: DynamicExecutor.IExecution): void;\n onReset(): void;\n options: IOptions;\n }\n\n export interface IOptions {\n reset: boolean;\n simultaneous: number;\n include?: string[];\n exclude?: string[];\n }\n\n export const execute = async <T>(\n props: IProps<T>,\n ): Promise<DynamicExecutor.IReport> => {\n // RESET\n if (props.options.reset === true) {\n await MySetupWizard.schema();\n await MySetupWizard.seed();\n await props.onReset();\n }\n\n // OPEN BACKEND\n const backend: T = await props.open(props.options);\n const connection: api.IConnection = {\n host: `http://127.0.0.1:${MyConfiguration.API_PORT()}`,\n };\n\n // DO TEST\n const report: DynamicExecutor.IReport = await DynamicExecutor.validate({\n prefix: \"test\",\n location: __dirname + \"/../features\",\n parameters: () => [\n {\n host: connection.host,\n } satisfies api.IConnection,\n ],\n filter: (func) =>\n (!props.options.include?.length ||\n (props.options.include ?? []).some((str) => func.includes(str))) &&\n (!props.options.exclude?.length ||\n (props.options.exclude ?? []).every((str) => !func.includes(str))),\n onComplete: props.onComplete,\n simultaneous: props.options.simultaneous,\n extension: __filename.split(\".\").pop()!,\n });\n\n // TERMINATE\n await sleep_for(2500);\n await props.close(backend);\n return report;\n };\n}\n", "test/helpers/TestAutomationStdio.ts": "import { DynamicExecutor } from \"@nestia/e2e\";\nimport chalk from \"chalk\";\n\nimport { ArgumentParser } from \"./ArgumentParser\";\nimport { TestAutomation } from \"./TestAutomation\";\n\nexport namespace TestAutomationStdio {\n export const getOptions = () =>\n ArgumentParser.parse<TestAutomation.IOptions>(\n async (command, prompt, action) => {\n command.option(\"--reset <true|false>\", \"reset local DB or not\");\n command.option(\n \"--simultaneous <number>\",\n \"number of simultaneous requests\",\n );\n command.option(\"--include <string...>\", \"include feature files\");\n command.option(\"--exclude <string...>\", \"exclude feature files\");\n\n return action(async (options) => {\n // reset\n if (typeof options.reset === \"string\")\n options.reset = options.reset === \"true\";\n options.reset ??= await prompt.boolean(\"reset\")(\"Reset local DB\");\n\n // simultaneous\n options.simultaneous = Number(\n options.simultaneous ??\n (await prompt.number(\"simultaneous\")(\n \"Number of simultaneous requests to make\",\n )),\n );\n if (isNaN(options.simultaneous) || options.simultaneous <= 0)\n options.simultaneous = 1;\n return options as TestAutomation.IOptions;\n });\n },\n );\n\n export const onComplete = (exec: DynamicExecutor.IExecution): void => {\n const trace = (str: string) =>\n console.log(` - ${chalk.green(exec.name)}: ${str}`);\n if (exec.error === null) {\n const elapsed: number =\n new Date(exec.completed_at).getTime() -\n new Date(exec.started_at).getTime();\n trace(`${chalk.yellow(elapsed.toLocaleString())} ms`);\n } else trace(chalk.red(exec.error.name));\n };\n\n export const onReset = (start: Date) => (): void => {\n const now: Date = new Date();\n console.log(\n ` - Reset DB: ${(now.getDate() - start.getDate()).toLocaleString()} ms`,\n );\n };\n\n export const report = (report: DynamicExecutor.IReport): void => {\n const exceptions: Error[] = report.executions\n .filter((exec) => exec.error !== null)\n .map((exec) => exec.error!);\n if (exceptions.length === 0) {\n console.log(\"Success\");\n console.log(\"Elapsed time\", report.time.toLocaleString(), `ms`);\n } else {\n for (const exp of exceptions) console.log(exp);\n console.log(\"Failed\");\n console.log(\"Elapsed time\", report.time.toLocaleString(), `ms`);\n process.exit(-1);\n }\n };\n}\n", "test/index.ts": "import { MyBackend } from \"../src/MyBackend\";\nimport { MyGlobal } from \"../src/MyGlobal\";\nimport { TestAutomation } from \"./helpers/TestAutomation\";\nimport { TestAutomationStdio } from \"./helpers/TestAutomationStdio\";\n\nconst main = async (): Promise<void> => {\n MyGlobal.testing = true;\n await TestAutomation.execute({\n open: async () => {\n const backend: MyBackend = new MyBackend();\n await backend.open();\n return backend;\n },\n close: (backend) => backend.close(),\n options: await TestAutomationStdio.getOptions(),\n onComplete: TestAutomationStdio.onComplete,\n onReset: TestAutomationStdio.onReset(new Date()),\n });\n};\nmain().catch((exp) => {\n console.log(exp);\n process.exit(-1);\n});\n", "test/webpack.ts": "import cp from \"child_process\";\nimport { sleep_for } from \"tstl\";\n\nimport { MyConfiguration } from \"../src/MyConfiguration\";\nimport { MyGlobal } from \"../src/MyGlobal\";\nimport { TestAutomation } from \"./helpers/TestAutomation\";\nimport { TestAutomationStdio } from \"./helpers/TestAutomationStdio\";\n\nconst wait = async (): Promise<void> => {\n while (true)\n try {\n await fetch(`http://localhost:${MyConfiguration.API_PORT()}/dsafdsafsd`);\n return;\n } catch (exp) {\n await sleep_for(100);\n }\n};\n\nconst main = async (): Promise<void> => {\n MyGlobal.testing = true;\n await TestAutomation.execute({\n open: async () => {\n const backend: cp.ChildProcess = cp.fork(\n `${MyConfiguration.ROOT}/dist/server.js`,\n {\n cwd: `${MyConfiguration.ROOT}/dist`,\n },\n );\n await wait();\n return backend;\n },\n close: async (backend) => {\n backend.kill();\n },\n options: await TestAutomationStdio.getOptions(),\n onComplete: TestAutomationStdio.onComplete,\n onReset: TestAutomationStdio.onReset(new Date()),\n });\n};\nmain().catch((exp) => {\n console.log(exp);\n process.exit(-1);\n});\n", "tsconfig.json": "{\n \"compilerOptions\": {\n /* Visit https://aka.ms/tsconfig to read more about this file */\n\n /* Projects */\n // \"incremental\": true, /* Save .tsbuildinfo files to allow for incremental compilation of projects. */\n // \"composite\": true, /* Enable constraints that allow a TypeScript project to be used with project references. */\n // \"tsBuildInfoFile\": \"./.tsbuildinfo\", /* Specify the path to .tsbuildinfo incremental compilation file. */\n // \"disableSourceOfProjectReferenceRedirect\": true, /* Disable preferring source files instead of declaration files when referencing composite projects. */\n // \"disableSolutionSearching\": true, /* Opt a project out of multi-project reference checking when editing. */\n // \"disableReferencedProjectLoad\": true, /* Reduce the number of projects loaded automatically by TypeScript. */\n\n /* Language and Environment */\n \"target\": \"ES2015\", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */\n \"lib\": [\n \"DOM\",\n \"ESNext\",\n ], /* Specify a set of bundled library declaration files that describe the target runtime environment. */\n // \"jsx\": \"preserve\", /* Specify what JSX code is generated. */\n \"experimentalDecorators\": true, /* Enable experimental support for TC39 stage 2 draft decorators. */\n \"emitDecoratorMetadata\": true, /* Emit design-type metadata for decorated declarations in source files. */\n // \"jsxFactory\": \"\", /* Specify the JSX factory function used when targeting React JSX emit, e.g. 'React.createElement' or 'h'. */\n // \"jsxFragmentFactory\": \"\", /* Specify the JSX Fragment reference used for fragments when targeting React JSX emit e.g. 'React.Fragment' or 'Fragment'. */\n // \"jsxImportSource\": \"\", /* Specify module specifier used to import the JSX factory functions when using 'jsx: react-jsx*'. */\n // \"reactNamespace\": \"\", /* Specify the object invoked for 'createElement'. This only applies when targeting 'react' JSX emit. */\n // \"noLib\": true, /* Disable including any library files, including the default lib.d.ts. */\n // \"useDefineForClassFields\": true, /* Emit ECMAScript-standard-compliant class fields. */\n // \"moduleDetection\": \"auto\", /* Control what method is used to detect module-format JS files. */\n\n /* Modules */\n \"module\": \"commonjs\", /* Specify what module code is generated. */\n // \"rootDir\": \"./\", /* Specify the root folder within your source files. */\n // \"moduleResolution\": \"node\", /* Specify how TypeScript looks up a file from a given module specifier. */\n // \"baseUrl\": \"./\", /* Specify the base directory to resolve non-relative module names. */\n \"paths\": {\n \"@ORGANIZATION/PROJECT-api/lib/*\": [\"./src/api/*\"],\n \"@ORGANIZATION/PROJECT-api\": [\"./src/api\"],\n }, /* Specify a set of entries that re-map imports to additional lookup locations. */\n // \"rootDirs\": [], /* Allow multiple folders to be treated as one when resolving modules. */\n // \"typeRoots\": [], /* Specify multiple folders that act like './node_modules/@types'. */\n // \"types\": [], /* Specify type package names to be included without being referenced in a source file. */\n // \"allowUmdGlobalAccess\": true, /* Allow accessing UMD globals from modules. */\n // \"moduleSuffixes\": [], /* List of file name suffixes to search when resolving a module. */\n // \"resolveJsonModule\": true, /* Enable importing .json files. */\n // \"noResolve\": true, /* Disallow 'import's, 'require's or '<reference>'s from expanding the number of files TypeScript should add to a project. */\n\n /* JavaScript Support */\n // \"allowJs\": true, /* Allow JavaScript files to be a part of your program. Use the 'checkJS' option to get errors from these files. */\n // \"checkJs\": true, /* Enable error reporting in type-checked JavaScript files. */\n // \"maxNodeModuleJsDepth\": 1, /* Specify the maximum folder depth used for checking JavaScript files from 'node_modules'. Only applicable with 'allowJs'. */\n\n /* Emit */\n // \"declaration\": true, /* Generate .d.ts files from TypeScript and JavaScript files in your project. */\n // \"declarationMap\": true, /* Create sourcemaps for d.ts files. */\n // \"emitDeclarationOnly\": true, /* Only output d.ts files and not JavaScript files. */\n \"sourceMap\": true, /* Create source map files for emitted JavaScript files. */\n // \"outFile\": \"./\", /* Specify a file that bundles all outputs into one JavaScript file. If 'declaration' is true, also designates a file that bundles all .d.ts output. */\n \"outDir\": \"./lib\", /* Specify an output folder for all emitted files. */\n // \"removeComments\": true, /* Disable emitting comments. */\n // \"noEmit\": true, /* Disable emitting files from a compilation. */\n // \"importHelpers\": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */\n // \"importsNotUsedAsValues\": \"remove\", /* Specify emit/checking behavior for imports that are only used for types. */\n // \"downlevelIteration\": true, /* Emit more compliant, but verbose and less performant JavaScript for iteration. */\n // \"sourceRoot\": \"\", /* Specify the root path for debuggers to find the reference source code. */\n // \"mapRoot\": \"\", /* Specify the location where debugger should locate map files instead of generated locations. */\n // \"inlineSourceMap\": true, /* Include sourcemap files inside the emitted JavaScript. */\n // \"inlineSources\": true, /* Include source code in the sourcemaps inside the emitted JavaScript. */\n // \"emitBOM\": true, /* Emit a UTF-8 Byte Order Mark (BOM) in the beginning of output files. */\n \"newLine\": \"lf\", /* Set the newline character for emitting files. */\n \"stripInternal\": true, /* Disable emitting declarations that have '@internal' in their JSDoc comments. */\n // \"noEmitHelpers\": true, /* Disable generating custom helper functions like '__extends' in compiled output. */\n // \"noEmitOnError\": true, /* Disable emitting files if any type checking errors are reported. */\n // \"preserveConstEnums\": true, /* Disable erasing 'const enum' declarations in generated code. */\n // \"declarationDir\": \"./\", /* Specify the output directory for generated declaration files. */\n // \"preserveValueImports\": true, /* Preserve unused imported values in the JavaScript output that would otherwise be removed. */\n\n /* Interop Constraints */\n // \"isolatedModules\": true, /* Ensure that each file can be safely transpiled without relying on other imports. */\n // \"allowSyntheticDefaultImports\": true, /* Allow 'import x from y' when a module doesn't have a default export. */\n \"esModuleInterop\": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */\n // \"preserveSymlinks\": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */\n \"forceConsistentCasingInFileNames\": true, /* Ensure that casing is correct in imports. */\n\n /* Type Checking */\n \"strict\": true, /* Enable all strict type-checking options. */\n // \"noImplicitAny\": true, /* Enable error reporting for expressions and declarations with an implied 'any' type. */\n // \"strictNullChecks\": true, /* When type checking, take into account 'null' and 'undefined'. */\n // \"strictFunctionTypes\": true, /* When assigning functions, check to ensure parameters and the return values are subtype-compatible. */\n // \"strictBindCallApply\": true, /* Check that the arguments for 'bind', 'call', and 'apply' methods match the original function. */\n // \"strictPropertyInitialization\": true, /* Check for class properties that are declared but not set in the constructor. */\n // \"noImplicitThis\": true, /* Enable error reporting when 'this' is given the type 'any'. */\n // \"useUnknownInCatchVariables\": true, /* Default catch clause variables as 'unknown' instead of 'any'. */\n // \"alwaysStrict\": true, /* Ensure 'use strict' is always emitted. */\n \"noUnusedLocals\": true, /* Enable error reporting when local variables aren't read. */\n \"noUnusedParameters\": true, /* Raise an error when a function parameter isn't read. */\n // \"exactOptionalPropertyTypes\": true, /* Interpret optional property types as written, rather than adding 'undefined'. */\n \"noImplicitReturns\": true, /* Enable error reporting for codepaths that do not explicitly return in a function. */\n \"noFallthroughCasesInSwitch\": true, /* Enable error reporting for fallthrough cases in switch statements. */\n // \"noUncheckedIndexedAccess\": true, /* Add 'undefined' to a type when accessed using an index. */\n // \"noImplicitOverride\": true, /* Ensure overriding members in derived classes are marked with an override modifier. */\n // \"noPropertyAccessFromIndexSignature\": true, /* Enforces using indexed accessors for keys declared using an indexed type. */\n // \"allowUnusedLabels\": true, /* Disable error reporting for unused labels. */\n // \"allowUnreachableCode\": true, /* Disable error reporting for unreachable code. */\n\n /* Completeness */\n // \"skipDefaultLibCheck\": true, /* Skip type checking .d.ts files that are included with TypeScript. */\n \"skipLibCheck\": true, /* Skip type checking all .d.ts files. */\n \"plugins\": [\n { \"transform\": \"typescript-transform-paths\" },\n { \"transform\": \"typia/lib/transform\" },\n { \n \"transform\": \"@nestia/core/lib/transform\",\n /**\n * Validate request body.\n * \n * - \"assert\": Use typia.assert() function\n * - \"is\": Use typia.is() function\n * - \"validate\": Use typia.validate() function\n * - \"assertEquals\": Use typia.assertEquals() function\n * - \"equals\": Use typia.equals() function\n * - \"validateEquals\": Use typia.validateEquals() function\n */\n \"validate\": \"validate\",\n /**\n * Validate JSON typed response body.\n * \n * - \"assert\": Use typia.assertStringify() function\n * - \"is\": Use typia.isStringify() function\n * - \"validate\": Use typia.validateStringify() function\n * - \"validate.log\": typia.validateStringify(), but do not throw and just log it\n * - \"stringify\": Use typia.stringify() function, but dangerous\n * - null: Just use JSON.stringify() function, without boosting\n */\n \"stringify\": \"assert\",\n },\n ]\n },\n \"include\": [\n \"src\"\n ],\n \"exclude\": [\n \"node_modules\",\n \"packages\",\n ]\n}\n" };