@autobe/compiler 0.9.2 → 0.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (95) hide show
  1. package/lib/AutoBeCompiler.d.ts +2 -1
  2. package/lib/AutoBeCompiler.js +2 -0
  3. package/lib/AutoBeCompiler.js.map +1 -1
  4. package/lib/AutoBeInterfaceCompiler.js +7 -125
  5. package/lib/AutoBeInterfaceCompiler.js.map +1 -1
  6. package/lib/AutoBePrismaCompiler.d.ts +2 -2
  7. package/lib/AutoBeTestCompiler.d.ts +8 -0
  8. package/lib/AutoBeTestCompiler.js +86 -0
  9. package/lib/AutoBeTestCompiler.js.map +1 -0
  10. package/lib/AutoBeTypeScriptCompiler.d.ts +2 -2
  11. package/lib/AutoBeTypeScriptCompiler.js +3 -3
  12. package/lib/AutoBeTypeScriptCompiler.js.map +1 -1
  13. package/lib/index.d.ts +3 -2
  14. package/lib/index.js +3 -2
  15. package/lib/index.js.map +1 -1
  16. package/lib/interface/transformOpenApi.d.ts +3 -0
  17. package/lib/interface/transformOpenApi.js +56 -0
  18. package/lib/interface/transformOpenApi.js.map +1 -0
  19. package/lib/prisma/validatePrismaApplication.js +9 -9
  20. package/lib/prisma/validatePrismaApplication.js.map +1 -1
  21. package/lib/prisma/writePrismaApplication.js +3 -3
  22. package/lib/prisma/writePrismaApplication.js.map +1 -1
  23. package/lib/raw/AutoBeCompilerTemplate.js +3 -0
  24. package/lib/raw/AutoBeCompilerTemplate.js.map +1 -1
  25. package/lib/raw/{external.json → nestjs.json} +67 -67
  26. package/lib/raw/test.json +1252 -0
  27. package/lib/test/programmers/AutoBeTestAccessorProgrammer.d.ts +8 -0
  28. package/lib/test/programmers/AutoBeTestAccessorProgrammer.js +19 -0
  29. package/lib/test/programmers/AutoBeTestAccessorProgrammer.js.map +1 -0
  30. package/lib/test/programmers/AutoBeTestFunctionalProgrammer.d.ts +12 -0
  31. package/lib/test/programmers/AutoBeTestFunctionalProgrammer.js +29 -0
  32. package/lib/test/programmers/AutoBeTestFunctionalProgrammer.js.map +1 -0
  33. package/lib/test/programmers/AutoBeTestLiteralProgrammer.d.ts +12 -0
  34. package/lib/test/programmers/AutoBeTestLiteralProgrammer.js +24 -0
  35. package/lib/test/programmers/AutoBeTestLiteralProgrammer.js.map +1 -0
  36. package/lib/test/programmers/AutoBeTestOperatorProgrammer.d.ts +10 -0
  37. package/lib/test/programmers/AutoBeTestOperatorProgrammer.js +38 -0
  38. package/lib/test/programmers/AutoBeTestOperatorProgrammer.js.map +1 -0
  39. package/lib/test/programmers/AutoBeTestPredicateProgrammer.d.ts +9 -0
  40. package/lib/test/programmers/AutoBeTestPredicateProgrammer.js +84 -0
  41. package/lib/test/programmers/AutoBeTestPredicateProgrammer.js.map +1 -0
  42. package/lib/test/programmers/AutoBeTestRandomProgrammer.d.ts +14 -0
  43. package/lib/test/programmers/AutoBeTestRandomProgrammer.js +151 -0
  44. package/lib/test/programmers/AutoBeTestRandomProgrammer.js.map +1 -0
  45. package/lib/test/programmers/AutoBeTestStatementProgrammer.d.ts +11 -0
  46. package/lib/test/programmers/AutoBeTestStatementProgrammer.js +81 -0
  47. package/lib/test/programmers/AutoBeTestStatementProgrammer.js.map +1 -0
  48. package/lib/test/programmers/IAutoBeTestApiFunction.d.ts +5 -0
  49. package/lib/test/programmers/IAutoBeTestApiFunction.js +3 -0
  50. package/lib/test/programmers/IAutoBeTestApiFunction.js.map +1 -0
  51. package/lib/test/programmers/IAutoBeTestProgrammerContext.d.ts +9 -0
  52. package/lib/test/programmers/IAutoBeTestProgrammerContext.js +3 -0
  53. package/lib/test/programmers/IAutoBeTestProgrammerContext.js.map +1 -0
  54. package/lib/test/programmers/writeTestExpression.d.ts +4 -0
  55. package/lib/test/programmers/writeTestExpression.js +13 -0
  56. package/lib/test/programmers/writeTestExpression.js.map +1 -0
  57. package/lib/test/programmers/writeTestFunction.d.ts +2 -0
  58. package/lib/test/programmers/writeTestFunction.js +63 -0
  59. package/lib/test/programmers/writeTestFunction.js.map +1 -0
  60. package/lib/test/programmers/writeTestStatement.d.ts +4 -0
  61. package/lib/test/programmers/writeTestStatement.js +10 -0
  62. package/lib/test/programmers/writeTestStatement.js.map +1 -0
  63. package/lib/utils/FilePrinter.d.ts +10 -0
  64. package/lib/utils/FilePrinter.js +54 -0
  65. package/lib/utils/FilePrinter.js.map +1 -0
  66. package/package.json +8 -7
  67. package/src/AutoBeCompiler.ts +4 -0
  68. package/src/AutoBeInterfaceCompiler.ts +8 -133
  69. package/src/AutoBePrismaCompiler.ts +2 -2
  70. package/src/AutoBeTestCompiler.ts +95 -0
  71. package/src/AutoBeTypeScriptCompiler.ts +7 -7
  72. package/src/index.ts +3 -2
  73. package/src/interface/transformOpenApi.ts +54 -0
  74. package/src/prisma/validatePrismaApplication.ts +1 -1
  75. package/src/prisma/writePrismaApplication.ts +1 -1
  76. package/src/raw/AutoBeCompilerTemplate.ts +3 -0
  77. package/src/raw/{external.json → nestjs.json} +67 -67
  78. package/src/raw/test.json +1252 -0
  79. package/src/test/programmers/AutoBeTestAccessorProgrammer.ts +42 -0
  80. package/src/test/programmers/AutoBeTestFunctionalProgrammer.ts +87 -0
  81. package/src/test/programmers/AutoBeTestLiteralProgrammer.ts +65 -0
  82. package/src/test/programmers/AutoBeTestOperatorProgrammer.ts +84 -0
  83. package/src/test/programmers/AutoBeTestPredicateProgrammer.ts +127 -0
  84. package/src/test/programmers/AutoBeTestRandomProgrammer.ts +314 -0
  85. package/src/test/programmers/AutoBeTestStatementProgrammer.ts +154 -0
  86. package/src/test/programmers/IAutoBeTestApiFunction.ts +6 -0
  87. package/src/test/programmers/IAutoBeTestProgrammerContext.ts +11 -0
  88. package/src/test/programmers/writeTestExpression.ts +24 -0
  89. package/src/test/programmers/writeTestFunction.ts +100 -0
  90. package/src/test/programmers/writeTestStatement.ts +15 -0
  91. package/src/utils/FilePrinter.ts +56 -0
  92. package/lib/utils/StringUtil.d.ts +0 -4
  93. package/lib/utils/StringUtil.js +0 -43
  94. package/lib/utils/StringUtil.js.map +0 -1
  95. package/src/utils/StringUtil.ts +0 -45
@@ -0,0 +1,9 @@
1
+ import { AutoBeOpenApi } from "@autobe/interface";
2
+ import { NestiaMigrateImportProgrammer } from "@nestia/migrate/lib/programmers/NestiaMigrateImportProgrammer";
3
+ import { HashMap } from "tstl";
4
+ import { IAutoBeTestApiFunction } from "./IAutoBeTestApiFunction";
5
+ export interface IAutoBeTestProgrammerContext {
6
+ importer: NestiaMigrateImportProgrammer;
7
+ document: AutoBeOpenApi.IDocument;
8
+ endpoints: HashMap<AutoBeOpenApi.IEndpoint, IAutoBeTestApiFunction>;
9
+ }
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=IAutoBeTestProgrammerContext.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"IAutoBeTestProgrammerContext.js","sourceRoot":"","sources":["../../../src/test/programmers/IAutoBeTestProgrammerContext.ts"],"names":[],"mappings":""}
@@ -0,0 +1,4 @@
1
+ import { AutoBeTest } from "@autobe/interface";
2
+ import ts from "typescript";
3
+ import { IAutoBeTestProgrammerContext } from "./IAutoBeTestProgrammerContext";
4
+ export declare const writeTestExpression: (ctx: IAutoBeTestProgrammerContext, expr: AutoBeTest.IExpression) => ts.Expression;
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.writeTestExpression = void 0;
4
+ const AutoBeTestAccessorProgrammer_1 = require("./AutoBeTestAccessorProgrammer");
5
+ const AutoBeTestFunctionalProgrammer_1 = require("./AutoBeTestFunctionalProgrammer");
6
+ const AutoBeTestLiteralProgrammer_1 = require("./AutoBeTestLiteralProgrammer");
7
+ const AutoBeTestOperatorProgrammer_1 = require("./AutoBeTestOperatorProgrammer");
8
+ const AutoBeTestPredicateProgrammer_1 = require("./AutoBeTestPredicateProgrammer");
9
+ const AutoBeTestRandomProgrammer_1 = require("./AutoBeTestRandomProgrammer");
10
+ const writeTestExpression = (ctx, expr) => factory[expr.type](ctx, expr);
11
+ exports.writeTestExpression = writeTestExpression;
12
+ const factory = Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, AutoBeTestLiteralProgrammer_1.AutoBeTestLiteralProgrammer), AutoBeTestOperatorProgrammer_1.AutoBeTestOperatorProgrammer), AutoBeTestAccessorProgrammer_1.AutoBeTestAccessorProgrammer), AutoBeTestFunctionalProgrammer_1.AutoBeTestFunctionalProgrammer), AutoBeTestRandomProgrammer_1.AutoBeTestRandomProgrammer), AutoBeTestPredicateProgrammer_1.AutoBeTestPredicateProgrammer);
13
+ //# sourceMappingURL=writeTestExpression.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"writeTestExpression.js","sourceRoot":"","sources":["../../../src/test/programmers/writeTestExpression.ts"],"names":[],"mappings":";;;AAGA,iFAA8E;AAC9E,qFAAkF;AAClF,+EAA4E;AAC5E,iFAA8E;AAC9E,mFAAgF;AAChF,6EAA0E;AAGnE,MAAM,mBAAmB,GAAG,CACjC,GAAiC,EACjC,IAA4B,EACb,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,IAAW,CAAC,CAAC;AAH5C,QAAA,mBAAmB,uBAGyB;AAEzD,MAAM,OAAO,2FACR,yDAA2B,GAC3B,2DAA4B,GAC5B,2DAA4B,GAC5B,+DAA8B,GAC9B,uDAA0B,GAC1B,6DAA6B,CACjC,CAAC"}
@@ -0,0 +1,2 @@
1
+ import { IAutoBeTestWriteProps } from "@autobe/interface";
2
+ export declare function writeTestFunction(props: IAutoBeTestWriteProps): string;
@@ -0,0 +1,63 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.writeTestFunction = writeTestFunction;
7
+ const utils_1 = require("@autobe/utils");
8
+ const NestiaMigrateImportProgrammer_1 = require("@nestia/migrate/lib/programmers/NestiaMigrateImportProgrammer");
9
+ const openapi_1 = require("@samchon/openapi");
10
+ const tstl_1 = require("tstl");
11
+ const typescript_1 = __importDefault(require("typescript"));
12
+ const transformOpenApi_1 = require("../../interface/transformOpenApi");
13
+ const FilePrinter_1 = require("../../utils/FilePrinter");
14
+ const AutoBeTestStatementProgrammer_1 = require("./AutoBeTestStatementProgrammer");
15
+ function writeTestFunction(props) {
16
+ const ctx = {
17
+ importer: new NestiaMigrateImportProgrammer_1.NestiaMigrateImportProgrammer(),
18
+ document: props.document,
19
+ endpoints: associate(props.document),
20
+ };
21
+ const decla = typescript_1.default.factory.createFunctionDeclaration([
22
+ typescript_1.default.factory.createModifier(typescript_1.default.SyntaxKind.ExportKeyword),
23
+ typescript_1.default.factory.createModifier(typescript_1.default.SyntaxKind.AsyncKeyword),
24
+ ], undefined, props.scenario.functionName, undefined, [
25
+ typescript_1.default.factory.createParameterDeclaration(undefined, undefined, "connection", undefined, typescript_1.default.factory.createTypeReferenceNode(`${ctx.importer.external({
26
+ type: "default",
27
+ name: "api",
28
+ library: `@ORGANIZATION/PROJECT-api`,
29
+ })}.IConnection`)),
30
+ ], undefined, AutoBeTestStatementProgrammer_1.AutoBeTestStatementProgrammer.block(ctx, {
31
+ type: "block",
32
+ statements: props.function.statements,
33
+ }));
34
+ return FilePrinter_1.FilePrinter.write({
35
+ statements: [
36
+ ...ctx.importer.toStatements((key) => `@ORGANIZATION/PROJECT-api/lib/structures/${key}`),
37
+ FilePrinter_1.FilePrinter.newLine(),
38
+ FilePrinter_1.FilePrinter.description(decla, props.scenario.draft),
39
+ ],
40
+ });
41
+ }
42
+ function associate(document) {
43
+ // associate operations and functions
44
+ const operations = new tstl_1.HashMap(document.operations.map((o) => new tstl_1.Pair({
45
+ method: o.method,
46
+ path: o.path,
47
+ }, o)), utils_1.AutoBeEndpointComparator.hashCode, utils_1.AutoBeEndpointComparator.equals);
48
+ const functions = new tstl_1.HashMap(utils_1.AutoBeEndpointComparator.hashCode, utils_1.AutoBeEndpointComparator.equals);
49
+ // from migrate application
50
+ const migrate = openapi_1.HttpMigration.application((0, transformOpenApi_1.transformOpenApiDocument)(document));
51
+ for (const route of migrate.routes) {
52
+ const endpoint = {
53
+ path: route.path,
54
+ method: route.method,
55
+ };
56
+ functions.emplace(endpoint, {
57
+ accessor: "api.functional." + route.accessor.join("."),
58
+ operation: operations.get(endpoint),
59
+ });
60
+ }
61
+ return functions;
62
+ }
63
+ //# sourceMappingURL=writeTestFunction.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"writeTestFunction.js","sourceRoot":"","sources":["../../../src/test/programmers/writeTestFunction.ts"],"names":[],"mappings":";;;;;AAaA,8CA4CC;AAxDD,yCAAyD;AACzD,iHAA8G;AAC9G,8CAA0E;AAC1E,+BAAqC;AACrC,4DAAqD;AAErD,uEAA4E;AAC5E,yDAAsD;AACtD,mFAAgF;AAIhF,SAAgB,iBAAiB,CAAC,KAA4B;IAC5D,MAAM,GAAG,GAAiC;QACxC,QAAQ,EAAE,IAAI,6DAA6B,EAAE;QAC7C,QAAQ,EAAE,KAAK,CAAC,QAAQ;QACxB,SAAS,EAAE,SAAS,CAAC,KAAK,CAAC,QAAQ,CAAC;KACrC,CAAC;IACF,MAAM,KAAK,GAAwB,oBAAE,CAAC,OAAO,CAAC,yBAAyB,CACrE;QACE,oBAAE,CAAC,OAAO,CAAC,cAAc,CAAC,oBAAE,CAAC,UAAU,CAAC,aAAa,CAAC;QACtD,oBAAE,CAAC,OAAO,CAAC,cAAc,CAAC,oBAAE,CAAC,UAAU,CAAC,YAAY,CAAC;KACtD,EACD,SAAS,EACT,KAAK,CAAC,QAAQ,CAAC,YAAY,EAC3B,SAAS,EACT;QACE,oBAAE,CAAC,OAAO,CAAC,0BAA0B,CACnC,SAAS,EACT,SAAS,EACT,YAAY,EACZ,SAAS,EACT,oBAAE,CAAC,OAAO,CAAC,uBAAuB,CAChC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A4B;YACxC,IAAI,EAAE,KAAK,CAAC,IAAI;YAChB,MAAM,EAAE,KAAK,CAAC,MAAe;SAC9B,CAAC;QACF,SAAS,CAAC,OAAO,CAAC,QAAQ,EAAE;YAC1B,QAAQ,EAAE,iBAAiB,GAAG,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,GAAG,CAAC;YACtD,SAAS,EAAE,UAAU,CAAC,GAAG,CAAC,QAAQ,CAAC;SACpC,CAAC,CAAC;IACL,CAAC;IACD,OAAO,SAAS,CAAC;AACnB,CAAC"}
@@ -0,0 +1,4 @@
1
+ import { AutoBeTest } from "@autobe/interface";
2
+ import ts from "typescript";
3
+ import { IAutoBeTestProgrammerContext } from "./IAutoBeTestProgrammerContext";
4
+ export declare const writeTestStatement: (ctx: IAutoBeTestProgrammerContext, stmt: AutoBeTest.IStatement) => ts.Statement[];
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.writeTestStatement = void 0;
4
+ const AutoBeTestStatementProgrammer_1 = require("./AutoBeTestStatementProgrammer");
5
+ const writeTestStatement = (ctx, stmt) => {
6
+ const next = AutoBeTestStatementProgrammer_1.AutoBeTestStatementProgrammer[stmt.type](ctx, stmt);
7
+ return Array.isArray(next) ? next : [next];
8
+ };
9
+ exports.writeTestStatement = writeTestStatement;
10
+ //# sourceMappingURL=writeTestStatement.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"writeTestStatement.js","sourceRoot":"","sources":["../../../src/test/programmers/writeTestStatement.ts"],"names":[],"mappings":";;;AAGA,mFAAgF;AAGzE,MAAM,kBAAkB,GAAG,CAChC,GAAiC,EACjC,IAA2B,EACX,EAAE;IAClB,MAAM,IAAI,GAAkC,6DAA6B,CACvE,IAAI,CAAC,IAAI,CACV,CAAC,GAAG,EAAE,IAAW,CAAC,CAAC;IACpB,OAAO,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;AAC7C,CAAC,CAAC;AARW,QAAA,kBAAkB,sBAQ7B"}
@@ -0,0 +1,10 @@
1
+ import ts from "typescript";
2
+ export declare namespace FilePrinter {
3
+ const description: <Node extends ts.Node>(node: Node, comment: string) => Node;
4
+ const newLine: () => ts.ExpressionStatement;
5
+ const write: (props: {
6
+ statements: ts.Statement[];
7
+ top?: string;
8
+ }) => string;
9
+ const beautify: (script: string) => Promise<string>;
10
+ }
@@ -0,0 +1,54 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.FilePrinter = void 0;
16
+ const prettier_plugin_sort_imports_1 = __importDefault(require("@trivago/prettier-plugin-sort-imports"));
17
+ const import2_1 = __importDefault(require("import2"));
18
+ const prettier_1 = require("prettier");
19
+ const typescript_1 = __importDefault(require("typescript"));
20
+ var FilePrinter;
21
+ (function (FilePrinter) {
22
+ FilePrinter.description = (node, comment) => {
23
+ if (comment.length === 0)
24
+ return node;
25
+ typescript_1.default.addSyntheticLeadingComment(node, typescript_1.default.SyntaxKind.MultiLineCommentTrivia, ["*", ...comment.split("\n").map((str) => ` * ${str}`), ""].join("\n"), true);
26
+ return node;
27
+ };
28
+ FilePrinter.newLine = () => typescript_1.default.factory.createExpressionStatement(typescript_1.default.factory.createIdentifier("\n"));
29
+ FilePrinter.write = (props) => {
30
+ var _a;
31
+ const script = typescript_1.default
32
+ .createPrinter({
33
+ newLine: typescript_1.default.NewLineKind.LineFeed,
34
+ })
35
+ .printFile(typescript_1.default.factory.createSourceFile(props.statements, typescript_1.default.factory.createToken(typescript_1.default.SyntaxKind.EndOfFileToken), typescript_1.default.NodeFlags.None));
36
+ return ((_a = props.top) !== null && _a !== void 0 ? _a : "") + script;
37
+ };
38
+ FilePrinter.beautify = (script) => __awaiter(this, void 0, void 0, function* () {
39
+ try {
40
+ return yield (0, prettier_1.format)(script, {
41
+ parser: "typescript",
42
+ plugins: [prettier_plugin_sort_imports_1.default, yield (0, import2_1.default)("prettier-plugin-jsdoc")],
43
+ importOrder: ["<THIRD_PARTY_MODULES>", "^[./]"],
44
+ importOrderSeparation: true,
45
+ importOrderSortSpecifiers: true,
46
+ importOrderParserPlugins: ["decorators-legacy", "typescript", "jsx"],
47
+ });
48
+ }
49
+ catch (_a) {
50
+ return script;
51
+ }
52
+ });
53
+ })(FilePrinter || (exports.FilePrinter = FilePrinter = {}));
54
+ //# sourceMappingURL=FilePrinter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"FilePrinter.js","sourceRoot":"","sources":["../../src/utils/FilePrinter.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,yGAA+D;AAC/D,sDAA8B;AAC9B,uCAAkC;AAClC,4DAA4B;AAE5B,IAAiB,WAAW,CAkD3B;AAlDD,WAAiB,WAAW;IACb,uBAAW,GAAG,CACzB,IAAU,EACV,OAAe,EACT,EAAE;QACR,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC;YAAE,OAAO,IAAI,CAAC;QACtC,oBAAE,CAAC,0BAA0B,CAC3B,IAAI,EACJ,oBAAE,CAAC,UAAU,CAAC,sBAAsB,EACpC,CAAC,GAAG,EAAE,GAAG,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,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;IACH,CAAC,CAAA,CAAC;AACJ,CAAC,EAlDgB,WAAW,2BAAX,WAAW,QAkD3B"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@autobe/compiler",
3
- "version": "0.9.2",
3
+ "version": "0.10.0",
4
4
  "description": "AI backend server code generator",
5
5
  "main": "lib/index.js",
6
6
  "author": "Wrtn Technologies",
@@ -13,9 +13,9 @@
13
13
  "url": "https://github.com/wrtnlabs/autobe/issues"
14
14
  },
15
15
  "dependencies": {
16
- "@nestia/core": "^7.0.0",
17
- "@nestia/migrate": "^7.0.0",
18
- "@samchon/openapi": "^4.3.3",
16
+ "@nestia/core": "^7.0.3",
17
+ "@nestia/migrate": "^7.0.3",
18
+ "@samchon/openapi": "^4.4.1",
19
19
  "@trivago/prettier-plugin-sort-imports": "^5.2.2",
20
20
  "embed-prisma": "^1.1.0",
21
21
  "embed-typescript": "^1.0.1",
@@ -24,8 +24,9 @@
24
24
  "prettier-plugin-jsdoc": "^1.3.2",
25
25
  "prisma-markdown": "^3.0.0",
26
26
  "tstl": "^3.0.0",
27
- "typia": "^9.3.1",
28
- "@autobe/interface": "^0.9.2"
27
+ "typia": "^9.4.0",
28
+ "@autobe/interface": "^0.10.0",
29
+ "@autobe/utils": "^0.10.0"
29
30
  },
30
31
  "devDependencies": {
31
32
  "@types/node": "^22.15.3",
@@ -34,7 +35,7 @@
34
35
  "ts-node": "^10.9.2",
35
36
  "ts-patch": "^3.3.0",
36
37
  "typescript": "~5.8.3",
37
- "@autobe/filesystem": "^0.9.2"
38
+ "@autobe/filesystem": "^0.10.0"
38
39
  },
39
40
  "keywords": [
40
41
  "ai",
@@ -2,11 +2,13 @@ import {
2
2
  IAutoBeCompiler,
3
3
  IAutoBeInterfaceCompiler,
4
4
  IAutoBePrismaCompiler,
5
+ IAutoBeTestCompiler,
5
6
  IAutoBeTypeScriptCompiler,
6
7
  } from "@autobe/interface";
7
8
 
8
9
  import { AutoBeInterfaceCompiler } from "./AutoBeInterfaceCompiler";
9
10
  import { AutoBePrismaCompiler } from "./AutoBePrismaCompiler";
11
+ import { AutoBeTestCompiler } from "./AutoBeTestCompiler";
10
12
  import { AutoBeTypeScriptCompiler } from "./AutoBeTypeScriptCompiler";
11
13
 
12
14
  /**
@@ -39,4 +41,6 @@ export class AutoBeCompiler implements IAutoBeCompiler {
39
41
 
40
42
  public readonly typescript: IAutoBeTypeScriptCompiler =
41
43
  new AutoBeTypeScriptCompiler();
44
+
45
+ public readonly test: IAutoBeTestCompiler = new AutoBeTestCompiler();
42
46
  }
@@ -1,18 +1,12 @@
1
1
  import { AutoBeOpenApi, IAutoBeInterfaceCompiler } from "@autobe/interface";
2
+ import { invertOpenApiDocument } from "@autobe/utils";
2
3
  import { NestiaMigrateApplication } from "@nestia/migrate";
3
- import {
4
- HttpMigration,
5
- IHttpMigrateApplication,
6
- OpenApi,
7
- OpenApiTypeChecker,
8
- OpenApiV3_1,
9
- } from "@samchon/openapi";
10
- import sortImport from "@trivago/prettier-plugin-sort-imports";
11
- import import2 from "import2";
12
- import { format } from "prettier";
4
+ import { OpenApi } from "@samchon/openapi";
13
5
 
6
+ import { transformOpenApiDocument } from "./interface/transformOpenApi";
14
7
  import { AutoBeCompilerTemplate } from "./raw/AutoBeCompilerTemplate";
15
8
  import { ArrayUtil } from "./utils/ArrayUtil";
9
+ import { FilePrinter } from "./utils/FilePrinter";
16
10
 
17
11
  /**
18
12
  * Custom Interface compiler that handles API specification and NestJS
@@ -41,7 +35,7 @@ export class AutoBeInterfaceCompiler implements IAutoBeInterfaceCompiler {
41
35
  public async compile(
42
36
  document: AutoBeOpenApi.IDocument,
43
37
  ): Promise<Record<string, string>> {
44
- const swagger: OpenApi.IDocument = transformDocument(document);
38
+ const swagger: OpenApi.IDocument = transformOpenApiDocument(document);
45
39
  const migrate: NestiaMigrateApplication = new NestiaMigrateApplication(
46
40
  swagger,
47
41
  );
@@ -61,7 +55,7 @@ export class AutoBeInterfaceCompiler implements IAutoBeInterfaceCompiler {
61
55
  async ([key, value]) => [
62
56
  key,
63
57
  key.endsWith(".ts") && key.endsWith(".d.ts") === false
64
- ? await beautify(value)
58
+ ? await FilePrinter.beautify(value)
65
59
  : value,
66
60
  ],
67
61
  ),
@@ -74,131 +68,12 @@ export class AutoBeInterfaceCompiler implements IAutoBeInterfaceCompiler {
74
68
  public async transform(
75
69
  document: AutoBeOpenApi.IDocument,
76
70
  ): Promise<OpenApi.IDocument> {
77
- return transformDocument(document);
71
+ return transformOpenApiDocument(document);
78
72
  }
79
73
 
80
74
  public async invert(
81
75
  document: OpenApi.IDocument,
82
76
  ): Promise<AutoBeOpenApi.IDocument> {
83
- return invertDocument(document);
77
+ return invertOpenApiDocument(document);
84
78
  }
85
79
  }
86
-
87
- async function beautify(script: string) {
88
- try {
89
- return await format(script, {
90
- parser: "typescript",
91
- plugins: [sortImport, await import2("prettier-plugin-jsdoc")],
92
- importOrder: ["<THIRD_PARTY_MODULES>", "^[./]"],
93
- importOrderSeparation: true,
94
- importOrderSortSpecifiers: true,
95
- importOrderParserPlugins: ["decorators-legacy", "typescript", "jsx"],
96
- });
97
- } catch {
98
- return script;
99
- }
100
- }
101
-
102
- function transformDocument(route: AutoBeOpenApi.IDocument): OpenApi.IDocument {
103
- const paths: Record<string, OpenApi.IPath> = {};
104
- for (const op of route.operations) {
105
- paths[op.path] ??= {};
106
- paths[op.path][op.method] = {
107
- summary: op.summary,
108
- description: op.description,
109
- parameters: op.parameters.map((p) => ({
110
- name: p.name,
111
- in: "path",
112
- schema: p.schema,
113
- description: p.description,
114
- required: true,
115
- })),
116
- requestBody: op.requestBody
117
- ? {
118
- content: {
119
- "application/json": {
120
- schema: {
121
- $ref: `#.components/schemas/${op.requestBody.typeName}`,
122
- },
123
- },
124
- },
125
- description: op.requestBody.description,
126
- required: true,
127
- }
128
- : undefined,
129
- responses: op.responseBody
130
- ? {
131
- [op.method === "post" ? 201 : 200]: {
132
- content: {
133
- "application/json": {
134
- schema: {
135
- $ref: `#/components/schemas/${op.responseBody.typeName}`,
136
- },
137
- },
138
- },
139
- description: op.responseBody.description,
140
- },
141
- }
142
- : undefined,
143
- };
144
- }
145
- return OpenApi.convert({
146
- openapi: "3.1.0",
147
- paths,
148
- components: route.components,
149
- } as OpenApiV3_1.IDocument);
150
- }
151
-
152
- function invertDocument(document: OpenApi.IDocument): AutoBeOpenApi.IDocument {
153
- const app: IHttpMigrateApplication = HttpMigration.application(document);
154
- return {
155
- operations: app.routes
156
- .filter((r) => r.query === null)
157
- .map(
158
- (r) =>
159
- ({
160
- specification: empty("specification"),
161
- method: r.method as "post",
162
- path: r.path,
163
- summary: r.operation().summary ?? empty("summary"),
164
- description: r.operation().description ?? empty("description"),
165
- parameters: r.parameters.map(
166
- (p) =>
167
- ({
168
- name: p.name,
169
- description:
170
- p.parameter().description ?? empty("description"),
171
- schema: p.schema as any,
172
- }) satisfies AutoBeOpenApi.IParameter,
173
- ),
174
- requestBody:
175
- r.body?.type === "application/json" &&
176
- OpenApiTypeChecker.isReference(r.body.schema)
177
- ? {
178
- description: r.body.description() ?? empty("description"),
179
- typeName: r.body.schema.$ref.split("/").pop()!,
180
- }
181
- : null,
182
- responseBody:
183
- r.success?.type === "application/json" &&
184
- OpenApiTypeChecker.isReference(r.success.schema)
185
- ? {
186
- description:
187
- r.success.description() ?? empty("description"),
188
- typeName: r.success.schema.$ref.split("/").pop()!,
189
- }
190
- : null,
191
- }) satisfies AutoBeOpenApi.IOperation,
192
- ),
193
- components: {
194
- schemas: (document.components?.schemas ?? {}) as Record<
195
- string,
196
- AutoBeOpenApi.IJsonSchemaDescriptive
197
- >,
198
- },
199
- };
200
- }
201
-
202
- function empty(key: string): string {
203
- return `Describe ${key} as much as possible with clear and concise words.`;
204
- }
@@ -1,8 +1,8 @@
1
1
  import {
2
2
  AutoBePrisma,
3
+ IAutoBePrismaCompileResult,
3
4
  IAutoBePrismaCompiler,
4
5
  IAutoBePrismaCompilerProps,
5
- IAutoBePrismaCompilerResult,
6
6
  IAutoBePrismaValidation,
7
7
  } from "@autobe/interface";
8
8
  import { EmbedPrisma } from "embed-prisma";
@@ -38,7 +38,7 @@ import { writePrismaApplication } from "./prisma/writePrismaApplication";
38
38
  export class AutoBePrismaCompiler implements IAutoBePrismaCompiler {
39
39
  public async compile(
40
40
  props: IAutoBePrismaCompilerProps,
41
- ): Promise<IAutoBePrismaCompilerResult> {
41
+ ): Promise<IAutoBePrismaCompileResult> {
42
42
  const compiler: EmbedPrisma = new EmbedPrisma();
43
43
  return compiler.compile(props.files);
44
44
  }
@@ -0,0 +1,95 @@
1
+ import {
2
+ AutoBeOpenApi,
3
+ IAutoBeTestCompiler,
4
+ IAutoBeTestValidateProps,
5
+ IAutoBeTestWriteProps,
6
+ IAutoBeTypeScriptCompileProps,
7
+ IAutoBeTypeScriptCompileResult,
8
+ } from "@autobe/interface";
9
+ import { AutoBeEndpointComparator, validateTestFunction } from "@autobe/utils";
10
+ import { EmbedTypeScript } from "embed-typescript";
11
+ import { HashMap, Pair } from "tstl";
12
+ import ts from "typescript";
13
+ import { IValidation } from "typia";
14
+ import typiaTransform from "typia/lib/transform";
15
+
16
+ import TestExternal from "./raw/test.json";
17
+ import { writeTestFunction } from "./test/programmers/writeTestFunction";
18
+ import { FilePrinter } from "./utils/FilePrinter";
19
+
20
+ export class AutoBeTestCompiler implements IAutoBeTestCompiler {
21
+ public async compile(
22
+ props: IAutoBeTypeScriptCompileProps,
23
+ ): Promise<IAutoBeTypeScriptCompileResult> {
24
+ const alias: string = props.package ?? "@ORGANIZATION/PROJECT-api";
25
+ const compiler: EmbedTypeScript = new EmbedTypeScript({
26
+ external: TestExternal as Record<string, string>,
27
+ compilerOptions: {
28
+ target: ts.ScriptTarget.ESNext,
29
+ module: ts.ModuleKind.CommonJS,
30
+ downlevelIteration: true,
31
+ baseUrl: "./",
32
+ paths: {
33
+ [alias]: ["./src/api"],
34
+ [`${alias}/lib/*`]: ["./src/api/*"],
35
+ },
36
+ strict: true,
37
+ skipLibCheck: true,
38
+ esModuleInterop: true,
39
+ experimentalDecorators: true,
40
+ emitDecoratorMetadata: true,
41
+ },
42
+ transformers: (program, diagnostics) => ({
43
+ before: [
44
+ typiaTransform(
45
+ program,
46
+ {},
47
+ {
48
+ addDiagnostic: (input) => diagnostics.push(input),
49
+ },
50
+ ),
51
+ ],
52
+ }),
53
+ });
54
+ return compiler.compile(props.files);
55
+ }
56
+
57
+ public async validate(
58
+ props: IAutoBeTestValidateProps,
59
+ ): Promise<IValidation.IError[] | null> {
60
+ const errors: IValidation.IError[] = [];
61
+ const endpoints: HashMap<
62
+ AutoBeOpenApi.IEndpoint,
63
+ AutoBeOpenApi.IOperation
64
+ > = new HashMap(
65
+ props.document.operations.map(
66
+ (op) =>
67
+ new Pair(
68
+ {
69
+ method: op.method,
70
+ path: op.path,
71
+ },
72
+ op,
73
+ ),
74
+ ),
75
+ AutoBeEndpointComparator.hashCode,
76
+ AutoBeEndpointComparator.equals,
77
+ );
78
+ validateTestFunction({
79
+ function: props.function,
80
+ document: props.document,
81
+ endpoints: endpoints,
82
+ errors,
83
+ });
84
+ return errors.length !== 0 ? errors : null;
85
+ }
86
+
87
+ public async write(props: IAutoBeTestWriteProps): Promise<string> {
88
+ const content: string = writeTestFunction(props);
89
+ return props.prettier === false ? content : FilePrinter.beautify(content);
90
+ }
91
+
92
+ public async getExternal(): Promise<Record<string, string>> {
93
+ return TestExternal as Record<string, string>;
94
+ }
95
+ }
@@ -1,14 +1,14 @@
1
1
  import {
2
+ IAutoBeTypeScriptCompileProps,
3
+ IAutoBeTypeScriptCompileResult,
2
4
  IAutoBeTypeScriptCompiler,
3
- IAutoBeTypeScriptCompilerProps,
4
- IAutoBeTypeScriptCompilerResult,
5
5
  } from "@autobe/interface";
6
6
  import nestiaCoreTransform from "@nestia/core/lib/transform";
7
7
  import { EmbedTypeScript } from "embed-typescript";
8
8
  import ts from "typescript";
9
9
  import typiaTransform from "typia/lib/transform";
10
10
 
11
- import EXTERNAL from "./raw/external.json";
11
+ import NestJSExternal from "./raw/nestjs.json";
12
12
 
13
13
  /**
14
14
  * Official TypeScript compiler for final code validation and quality assurance.
@@ -37,11 +37,11 @@ import EXTERNAL from "./raw/external.json";
37
37
  */
38
38
  export class AutoBeTypeScriptCompiler implements IAutoBeTypeScriptCompiler {
39
39
  public async compile(
40
- props: IAutoBeTypeScriptCompilerProps,
41
- ): Promise<IAutoBeTypeScriptCompilerResult> {
40
+ props: IAutoBeTypeScriptCompileProps,
41
+ ): Promise<IAutoBeTypeScriptCompileResult> {
42
42
  const alias: string = props.package ?? "@ORGANIZATION/PROJECT-api";
43
43
  const compiler: EmbedTypeScript = new EmbedTypeScript({
44
- external: EXTERNAL as Record<string, string>,
44
+ external: NestJSExternal as Record<string, string>,
45
45
  compilerOptions: {
46
46
  target: ts.ScriptTarget.ESNext,
47
47
  module: ts.ModuleKind.CommonJS,
@@ -83,6 +83,6 @@ export class AutoBeTypeScriptCompiler implements IAutoBeTypeScriptCompiler {
83
83
  }
84
84
 
85
85
  public async getExternal(location: string): Promise<string | undefined> {
86
- return (EXTERNAL as Record<string, string>)[location] ?? undefined;
86
+ return (NestJSExternal as Record<string, string>)[location] ?? undefined;
87
87
  }
88
88
  }
package/src/index.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  export * from "./AutoBeCompiler";
2
- export * from "./AutoBeTypeScriptCompiler";
3
- export * from "./AutoBeInterfaceCompiler";
4
2
  export * from "./AutoBePrismaCompiler";
3
+ export * from "./AutoBeInterfaceCompiler";
4
+ export * from "./AutoBeTestCompiler";
5
+ export * from "./AutoBeTypeScriptCompiler";